0

I'm using a ListView that is populated by a custom CursorAdapter that returns two different Views based on the value of the data in the Cursor for that particular row.

One View type contains a TextView, call it TextView1.
The second View contains TextView1 and TextView2.

The problem is I'd like the second View to be treated as two rows in the ListView. So Text1 would become a row and Text2 would become another row.

Obviously with Layouts I can make it look like it's a different row, but it's not actually a different row. I can't independently select them, so when I hook into the ListView's OnListItemClick event, I get a single event for clicking TextView1 and TextView2, they are not distinct. Is there a way I can tell the ListView that there are two rows here and not one or is there a way to fake it?

1
  • With CursorAdapter one cursor entry is one row, no other way to do it, I suppose. You can always write a custom extension of ArrayAdapter or even BaseAdapter Jul 24, 2012 at 8:29

1 Answer 1

0

Is there a way I can tell the ListView that there are two rows here and not one or is there a way to fake it?

You can approach this in two ways. First you could make your own custom Adapter that breaks the Cursor in the correct number of rows and then simple use one TextView per row with OnItemClickListener. Depending on the size of the Cursor's data, this could be easy or something to avoid.

The second approach would be to use your current custom CursorAdapter and implement two types of rows(implement the getViewTypeCount() and getItemViewType() methods), one with a simple TextView and a row with two TextViews. The trick would be that you can't use the OnItemClickListener on the ListView, instead you would set your on OnCLickListeners on the TextViews from the rows. If you make the TextViews to occupy the entire row's width and height the effect would be of a row being selected. In the OnClickListener for those TextViews you could pass the current position of the Cursor or the id for that row to do whatever you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.