views:

23

answers:

2

On iPhone you have something like this:

static NSString *Celldentifier = @"Section1_Cell";
 UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];

where the CellIdentifier is used to dequeue cells of a specific 'type' of cells. So if you have more than one sections in a tableview and the cells of each section follow a different design, you can define what 'type' of cell to dequeue based on their CellIdentifier. This then avoids reusing the wrong kind of cell for a section that needs to draw a different cell.

I wonder how this can be done on Android. I know you can reuse rows by overriding your Adapter's getView(...) method as below

@Override
public View getView(int position, View convertView, ViewGroup parent){
 View row = convertView;
 CustomRowWrapper wrapper = null;
 if (row == null){
           // inflate your row layout and create a new row object from it
        }

but this only works if all your cells are exactly the same. If you want to differentiate between row types this is not enough and you can see when scrolling through your list that the 'wrong' type of row is being reused in place of your different set of rows as there is nothing to tell the adapter what type of row to reuse.

Any suggestions then how this can be done on Android?

A: 

You can have multiple types of rows by implementing: getViewTypeCount() getItemViewType()

Damian Kołakowski
A: 

I think your question has already been answered here.

cement
Thanks, didn't come across that while searching. Probably should have used different search terms.
serk01