1

I have a:

public class MyList extends ListActivity {
    SimpleAdapter simpleAdapter;

Binding to the ListView is done by a ViewBinder:

    simpleAdapter = new SimpleAdapter(this, getData(path),
            R.layout.menu_row, new String[] { 
        ..., "checked" }, new int[] {..., R.id.checkBox1 });

    SimpleAdapter.ViewBinder viewBinder = new SimpleAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Object data,
                String textRepresentation) {
            if (view.getId() == R.id.checkBox1) {
                                CheckBox checkBox = (CheckBox) view;
                checkBox.setChecked(Boolean.parseBoolean((String) data));

My xml looks like this, clickable and focusable helps that the row behaves seen as one.

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:focusable="false"
    android:clickable="false"
    android:focusableInTouchMode="false"
     />

I also have a:

protected void onListItemClick(ListView l, View v, int position, long id) {

which interacts with the click event. This works good so far, my problem is when I click on a row, the CheckBox doesn't change its visual state. What can I do?

user
  • 86,916
  • 18
  • 197
  • 190
user1324936
  • 2,187
  • 4
  • 36
  • 49

2 Answers2

1

I think what you want to look into is a CheckedTextView which shows a check box and when a list item is clicked the check box changes

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • no i dont want to. my layout is much more complicated and there is no need for major changes. My feeling says there is only a small setting that fixes my problem – user1324936 May 18 '12 at 21:05
0

Put a button.setChecked(true) in you're onListItemClick ( or code to toggle back and forth using setChecked).

EDIT

Misunderstood your issue. Have you told the adapter that the dataset has been changed?

Barak
  • 16,318
  • 9
  • 52
  • 84
  • who is button? what i have is protected void onListItemClick(ListView l, View v, int position, long id) { CheckBox checkbox = (CheckBox) v.findViewById(R.id.checkBox1); checkbox.setChecked(!checkbox.isChecked()); but it showns no effect – user1324936 May 18 '12 at 21:16
  • 1
    Sorry, meant checkbox. Can you confirm the status is changing even if the graphic isn't? Have you tried notifyDatasetChanged (I think I got that right, I:m on my phone and away from resources) – Barak May 18 '12 at 21:18
  • yes i call simpleAdapter.notifyDataSetChanged(); that was the problem: it calls the getData method, which doesn't know of any check box changes. i commented it out, thanks your thoughts brought pointed me to the err – user1324936 May 18 '12 at 21:40