android - Android listview项目点击影响多个项目
问题描述
我有一个产品清单。我可以为每件商品设置订购数量。为此,我使用了对话框和项目位置。但是,当我为单个项目添加数量时,它会影响多个项目。
问题视频 我使用了下面的代码
sListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Dialog dialog = new Dialog(OrderEntryActivity.this);
dialog.setContentView(R.layout.order_qty_collect);
TextView tvpid= (TextView) view.findViewById(R.id.pId);
TextView tVpid= (TextView) dialog.findViewById(R.id.pcode);
PRODUCTID=tvpid.getText().toString();
tVpid.setText(PRODUCTID);
final TextView parentitemid= (TextView) dialog.findViewById(R.id.parentitemid);
parentitemid.setText( String.valueOf(position));
TextView tvpname= (TextView) view.findViewById(R.id.pName);
TextView tVpname= (TextView) dialog.findViewById(R.id.pName);
tVpname.setText(tvpname.getText());
TextView tvpprice= (TextView) view.findViewById(R.id.pPrice);
TextView tVpprice= (TextView) dialog.findViewById(R.id.pPrice);
TextView pQty= (TextView) dialog.findViewById(R.id.poQty);
tVpprice.setText(tvpprice.getText());
dialog.setCancelable(false);
dialog.show();
Button submit = (Button) dialog.findViewById(R.id.btn_qtySubmit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView PIid= (TextView) dialog.findViewById(R.id.parentitemid);
int ItemPogision =Integer.parseInt(PIid.getText().toString());
EditText qTy= (EditText) dialog.findViewById(R.id.qtyId);
String qtY=qTy.getText().toString();
if(qtY.equals("")){
Toast.makeText(OrderEntryActivity.this,"Order Quantity Blank. Please fillup.",Toast.LENGTH_SHORT).show();
}else{
Integer Qty= Integer.parseInt(qtY);
salesDB.deleteTmpOrderByPID(PRODUCTID);
Boolean x=salesDB.TmpOrderInsert(CUSTID,PRODUCTID,Qty);
if(x==true){
TextView pqty= (TextView) sListview.getChildAt(ItemPogision).findViewById(R.id.poQty);
pqty.setText(qtY);
sListview.getChildAt(ItemPogision).setBackgroundColor(Color.GREEN);
Toast.makeText(OrderEntryActivity.this,"Added to Cart",Toast.LENGTH_SHORT).show();
dialog.dismiss();
Count++;
count.setText(Count.toString());
}else{
Toast.makeText(OrderEntryActivity.this,"Fail to add into Cart",Toast.LENGTH_SHORT).show();
}
}
}
});
Button close = (Button) dialog.findViewById(R.id.btn_cancel);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
}
});
}
});
在视频中您可以看到,我已经为两种产品输入了订单数量,但它影响了项目列表中的多个产品。
解决方案
我完全不明白你在说什么但是,如果你想设置 ClickListeners 或在 ListView 的特定行或该行中的特定项目中做任何事情,你应该在 ListAdapter 中设置侦听器,这样就可以了.
推荐阅读
- python - Python3中的对象类在哪里
- tsql - 为什么我的 SQL ALL 运算符没有返回任何结果?
- javascript - 状态结果更改时如何添加警报声音
- ios - 如何将现有 iOS 应用升级到 Xamarin Forms 应用
- amazon-web-services - 如何将 AWS 开发工具包 (Javascript) 与 VueJS 一起使用?
- java - 如何将 jre 从 java 12.0.2 添加到 eclipse mars 4.5.2
- string - 在Scala中将带有前置0的字符串转换为Int
- javascript - “SyntaxError: Unexpected token ':'. 解析错误。” JSON & ajax
- html - 一个表格可以与电子邮件中的另一个表格重叠吗?
- linux - 来自另一个任务输出的 ansible set fact