0

I wish to disable a line item for my ListView (using SimpleCursorAdapter with ViewBinder), but it doesn't work:

public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
        int viewId = view.getId();
        switch (viewId) {
          case R.id.my_view_status_value:

int viewVal = cursor.getInt(columnIndex);

if(viewVal == 0) {
   //disable this line item
   view.getRootView().findViewById(R.id.line_item).setEnabled(false);
} else {
   //enable
   view.getRootView().findViewById(R.id.line_item).setEnabled(true);
}

When I remove else, it disables them randomly, when if-else exists, all are enabled. What is going on?

user
  • 86,916
  • 18
  • 197
  • 190
Taranfx
  • 10,361
  • 17
  • 77
  • 95

1 Answers1

1

It seems, that view.getRootView() returns topmost view (probably ListView), which contains many lines and all of them have id R.id.line_item. So it may return pretty random view. You can try get list item view using view.getParent()

Mikita Belahlazau
  • 15,326
  • 2
  • 38
  • 43