开发者

Reusing Android rows with iPhone-like CellIdentifiers?

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 dif开发者_StackOverflow中文版ferent 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜