【发布时间】:2016-06-21 07:27:33
【问题描述】:
我正在处理ListView 内部有EditText。我在ListView 的每个项目中使用了四个EditText。我在ListView 中获得EditText 的位置时遇到问题。下面是我的代码。我能够获取TextView 的位置,但是在获取EditText 的位置时我遇到了问题。
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
myproductpercarton = (TextView) view.findViewById(R.id.txtorderamount);
final String ssss =(String) ((TextView) view.findViewById(R.id.txtorderamount)).getText();
mytotalprice = (TextView) view.findViewById(R.id.txtprice);
mm = (CheckBox) view.findViewById(R.id.mycheck);
mm.setFocusableInTouchMode(true);
mm.setFocusable(true);
mm2 = (CheckBox) view.findViewById(R.id.mynewcheck);
mm2.setFocusableInTouchMode(true);
mm2.setFocusable(true);
myorderprice = (EditText) view.findViewById(R.id.txtorderby);
myorderprice.setFocusableInTouchMode(true);
myorderprice.setFocusable(true);
mycartonno = (EditText) view.findViewById(R.id.txtordercarton);
mycartonno.setFocusableInTouchMode(true);
mycartonno.setFocusable(true);
myproductno = (EditText) view.findViewById(R.id.txtproduct);
myproductno.setFocusableInTouchMode(true);
myproductno.setFocusable(true);
myproductno.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String myprodpercart;
map = (HashMap<String, String>) getListView().getItemAtPosition(position);
HashMap<String, String> map2 = (HashMap<String, String>) getListView().getItemAtPosition(position);
HashMap<String, String> map3 = (HashMap<String, String>) getListView().getItemAtPosition(position);
double orderId4;
double mycarton2;
double mynewcart;
double myprodno2;
double mycartquantity;
double mytotal;
String mynoocarton;
double mynoocarton44;
int myprodno3;
String temp=mycartonno.getText().toString();
String contents = mycartonno.getText().toString();
orderId4 = new Double(map.get(TAG_PRODUCTPERCARTON));
Log.d("MyOrderId :: ", String.valueOf(orderId4));
mycartonprice2 = map.get(TAG_PRODUCTPERCARTON2);
Log.d("MyCartonPrice :: ", String.valueOf(mycartonprice2));
mynoocarton = mycartonno.getText().toString();
mynoocarton44 = new Double(mycartonno.getText().toString());
mycarton2 = new Double(mynoocarton);
mynewcart = new Double(mycartonprice2);
myprodno2 = new Double(orderId4 * mycarton2);
myprodno3 = new Integer((int) myprodno2);
mycartquantity = new Double(mycartonno.getText().toString());
Log.d("MyCartonNo :: ", mycartonno.getText().toString());
Log.d("MyCartonNo2 :: ",contents);
mytotal = new Double(mycartquantity * mynewcart);
String mynoocarton3 = String.valueOf(mynoocarton44);
String total = String.valueOf(mytotal);
String mm = String.valueOf(myprodno3);
mycartonno.setText(mynoocarton3);
myproductno.setText(mm);
mytotalprice.setText(total);
Toast.makeText(getActivity(), ssss + " " + mynewcart + "----" + mm + " " + total,
Toast.LENGTH_SHORT).show();
}
});
mydiscount = (EditText) view.findViewById(R.id.txtdiscount);
mydiscount.setFocusableInTouchMode(true);
mydiscount.setFocusable(true);
}
});
【问题讨论】:
-
有什么问题?表示你无法获得位置?
-
您的列表项布局的共享代码
-
你面临什么“问题”?
-
我无法设置 myproductno.setText(mm) 的位置;意味着如果我在第三行输入值后位于第四行,如果我再次单击第三行的编辑文本,则从第四行开始行然后它向我显示第 4 行而不是第 3 行的值
-
首先你应该初始化你的 EditText 和你的适配器类里面你的自定义列表视图中的每个视图,而不是你的列表视图 itemClick。然后你应该为edittext和诸如此类的东西提供点击事件。你能提供你适配器类的代码吗...?
标签: android listview android-edittext listadapter simpleadapter