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?
You can approach this in two ways. First you could make your own custom
Adapterthat breaks theCursorin the correct number of rows and then simple use oneTextViewper row withOnItemClickListener. Depending on the size of theCursor‘s data, this could be easy or something to avoid.The second approach would be to use your current custom
CursorAdapterand implement two types of rows(implement thegetViewTypeCount()andgetItemViewType()methods), one with a simpleTextViewand a row with twoTextViews. The trick would be that you can’t use theOnItemClickListeneron theListView, instead you would set your onOnCLickListenerson theTextViewsfrom the rows. If you make theTextViewsto occupy the entire row’s width and height the effect would be of a row being selected. In theOnClickListenerfor thoseTextViewsyou could pass the current position of theCursoror theidfor that row to do whatever you want.