1

On checking a check box from a row in list view few other check boxes are also getting selected. (In android). Does anybody knows that why this problem is occurring? Here is my source code:

            dbHelper db1 = new dbHelper(WaterPopup.this);

    waterList = new ArrayList<HashMap<String, Object>>();

    map1 = new HashMap<String, Object>();

    Cursor c1 = db1.getMenuDetailsData(SubMenuID);
    c1.moveToFirst();
    while (c1.isAfterLast() == false) {

        if (c1.getString(3).substring(0).equals("I")) {
            map1.put("WaterOptionID", c1.getString(5).substring(0)) ;
              map1.put("CheckBox",cb);
              map1.put("WaterOptionName", c1.getString(0).substring(0));
              map1.put("MinusImg",R.drawable.minus_30+"");
              map1.put("Quantity","1");
              map1.put("PlusImg",R.drawable.plus_30+"");
              map1.put("Currency","$");
              map1.put("Price", c1.getString(2).substring(0));
              map1.put("OrderStatusImg",R.drawable.round_25+"");

            waterList.add(map1);
            map1 = new HashMap<String, Object>();
        }

        c1.moveToNext();
    }
    c1.close(); 


        mSchedule = new SimpleAdapter(WaterPopup.this, waterList, R.layout.waterlistitem,
                new String[] {"WaterOptionID","CheckBox", "WaterOptionName", "MinusImg", "Quantity","PlusImg","Currency", "Price", "OrderStatusImg"}, 
                   new int[] {R.id.wateroptionID_tv,R.id.orderWater_cb, R.id.wateroptionName_tv, R.id.minussign_btn, R.id.Qty_tv, R.id.plusimage_btn,R.id.currency_tv,R.id.price_tv,R.id.orderStatus_btn});
        OrderWaterItem.setAdapter(mSchedule);
Neha
  • 681
  • 2
  • 9
  • 15

2 Answers2

0

SimpleAdapter only support TextViews:

Description of the 'to'-parameter in the constructor:

"The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter."

pgsandstrom
  • 14,361
  • 13
  • 70
  • 104
0

You have to override the adapter. It is not hard. Look here:

http://www.geekmind.net/2009/11/android-custom-list-item-with-nested.html

and here:

Android: ListView elements with multiple clickable buttons

Community
  • 1
  • 1
Anthony Graglia
  • 5,355
  • 5
  • 46
  • 75
  • @Neha, perhaps you can edit you original question and explain your progress without getting rid of the original code and post the new code too. It is very difficult to look at in comments. But just so I am sure what you are asking, when you scroll, the boxes get unchecked when they leave the screen? And you only need one box checked? If it leaves the screen and is unchecked and you submit, does it behave as if it is unchecked? – Anthony Graglia Mar 11 '11 at 09:04
  • @trgraglia: yeah, you are right. I have checkbox on each row in my listview. When i scroll the list, the state of check boxes is lost. – Neha Mar 11 '11 at 11:21
  • @Neha, im not familiar with having widget objects in the custom adapter but perhaps you can set some breakpoints and debug and see if they are called each time the appear again. Then you could probably have a boolean on the adapter which is set and when the checkbox comes back into view, it checks the boolean and becomes checked or not. – Anthony Graglia Mar 11 '11 at 11:46
  • @trgraglia: I got my answer. This link helped me . http://stackoverflow.com/questions/4803756/android-cursoradapter-listview-and-checkbox/4804366#4804366 – Neha Mar 11 '11 at 11:55
  • I just added that link to your article because it gets hidden here and people wont see it... feel free to edit and format if you like. – Anthony Graglia Mar 11 '11 at 12:03