2013-05-13 24 views
0

您好我创建customlistview第一次添加一个按钮我插入值为0.当我必须单击该添加按钮值是1更改database.Getting列值结果。当我们在android中添加数据库时,Customlistview改变了按钮?

注* 获得价值成果1个单元变更按钮或color.I我在baseadapter使用 *

这里我提到的示例代码也:

  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)); 
        } 

       } 

      }); 

问题按钮被改变,但列表视图刷新意味着自动更改上一个按钮请给我解决方案

回答

0

我不完全确定我理解你的问题,但我相信你说按钮的价值正在改变,但它在列表中的观点没有适当地改变,对吗?

如果是这样,那是因为列表视图的适配器如何工作。它被设计成通过重复使用已经创建的膨胀视图来提高效率,而不是每次重新创建视图。

首先,尝试调用适配器上的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; 
} 
相关问题