当我们在android中添加数据库时,Customlistview更改了按钮?
您好,我已创建customlistview第一次在0中插入值时添加了一个按钮。当我必须单击该添加按钮时,数据库中的值1已更改。正在获取列值结果 注*获取值结果1意味着更改了按钮或颜色。我在baseadapter中使用* 这里我还提到了示例代码:当我们在android中添加数据库时,Customlistview更改了按钮?,android,Android,您好,我已创建customlistview第一次在0中插入值时添加了一个按钮。当我必须单击该添加按钮时,数据库中的值1已更改。正在获取列值结果 注*获取值结果1意味着更改了按钮或颜色。我在baseadapter中使用* 这里我还提到了示例代码: holder.btn_add.setOnClickListener(new OnClickListener() { @Override public void on
holder.btn_add.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("product", arrListproduct_name
.get(position).toString().trim());
hashMap.put(
"price",
getDoublePrecision(arrListproductprice
.get(position).toString().trim()));
hashMap.put("productID", arrlistproduct_id
.get(position).toString().trim());
hashMap.put("quantity", datavalue);
hashMap.put("resturantID",
category.dinein_restaurant_id);
hashMap.put("value", Str_value);
arrListproductdatabase.add(hashMap);
if (dataBase.ProductExist(
DatabaseHelper.TABLErestaurant,
arrlistproduct_id.get(position).toString()
.trim())) {
Toast.makeText(VegNonVegClass.this,
"Update successfully", Toast.LENGTH_LONG)
.show();
for (int i = 0; i < GetAllitemDetailsItem.size(); i++) {
dataBase.updateData1(
GetAllitemDetailsItem.get(i).get("id"),
DatabaseHelper.TABLErestaurant, "1");
}
} else {
dataBase.insertData(DatabaseHelper.TABLErestaurant,
arrListproductdatabase);
arrListproductdatabase.clear();
Toast.makeText(VegNonVegClass.this,
"Add successfully", Toast.LENGTH_LONG)
.show();
// arrListproductdatabase.remove(position);
// notifyDataSetChanged();
ArrayList<String> selectedno = dataBase
.getselectedTrue();
for (String s : selectedno) {
if (s.equalsIgnoreCase("1")) {
holder.btn_add
.setBackgroundResource(R.drawable.checkout);
}
}
}
if (listener != null) {
listener.totalAmount(String.valueOf(Str_subtotal));
}
}
});
holder.btn\u add.setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
//TODO自动生成的方法存根
HashMap HashMap=新的HashMap();
hashMap.put(“产品”,arrListproduct\u名称
.get(位置).toString().trim());
hashMap.put(
“价格”,
getDoublePrecision(arrListproductprice)
.get(position.toString().trim());
hashMap.put(“productID”,arrlistproduct\u id
.get(位置).toString().trim());
hashMap.put(“数量”,数据值);
hashMap.put(“resturantID”,
类别。餐厅(餐厅id);
hashMap.put(“值”,Str_值);
arrListproductdatabase.add(hashMap);
如果(dataBase.ProductExist)(
DatabaseHelper.TABLErestaurant,
arrlistproduct_id.get(position.toString())
.trim()){
Toast.makeText(vegnonegclass.this,
“更新成功”,Toast.LENGTH\u LONG)
.show();
对于(int i=0;i
问题按钮已更改,但listview刷新意味着自动更改以前的按钮请给我解决方案我不完全确定我是否理解您的问题,但我相信您是说按钮的值正在更改,但列表中的视图没有相应更改,对吗 如果是这样,那是因为列表视图的适配器是如何工作的。它的设计目的是通过重新使用已经创建的膨胀视图来提高效率,而不是每次都重新创建它们 首先,尝试在适配器上调用notifyDataSetChanged() 如果这不能更新您的问题,可能是因为您没有实际更改适配器中的数据;只是它所代表的价值 确保您也适当地重写了适配器的getView()方法:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row == null)
{
row = (((Activity)mContext).getLayoutInflater()).inflate(layoutResourceId, parent, false);
}
try{
// Set what the view should show here
}
catch(Exception e){
e.printStackTrace();
}
return row;
}