在Android的ListView的多种细胞类型 [英] Multiple Cell Types in Android ListView

查看:81
本文介绍了在Android的ListView的多种细胞类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是显示一些数据一本书像标题,作者和封面,而这些数据的下方,有包含可点击的章节列表一个ListView。

What I'm trying to do is to show some data for a book like Title, Author, and a Cover, and beneath these data, to have a ListView containing a list of clickable chapters.

我想过将有不同类型的细胞,其中第一个将包含数据的一个ListView,和他们的其余部分将是包含章节简单细胞的一种方式。 ListView控件绑定到实现NewView的(...)和bindView(...)方法,我不知道如何才能返回基于细胞的位置不同类型的细胞自定义定制CursorAdapter的。

One way I've thought would be to have a ListView with different type of cells, where the first would contain the data, and the rest of them would be simple cells containing the chapters. The ListView binds to a custom CursorAdapter that implements the newView(...) and bindView(...) methods, which I don't know how to customise in order to return different types of cells based on the cell's position.

@Override
public void bindView(View view, Context context, Cursor cursor) {

    TextView title = (TextView) view.findViewById(R.id.title);
    title.setText(cursor.getString(cursor.getColumnIndex(Constants.TITLE)));
    ..
}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(R.layout.bookcell, parent, false);
    bindView(v, context, cursor);
    return v;
}

我应该怎样做呢?

How should I do that?

谢谢!

推荐答案

您可以做到这一点:


  1. 重写 getViewTypeCount()并返回不同的行布局的数量

  2. 重写 getItemViewType()并返回该行布局的从零开始的索引被用于给定位置

  3. 调整 NewView的() bindView()来使用基于位置的右排型(例如, NewView的()膨胀根据位置
  4. 不同的行布局
  1. Overriding getViewTypeCount() and returning the number of distinct row layouts
  2. Overriding getItemViewType() and returning a 0-based index of the row layout to be used for a given position
  3. Adjusting newView() and bindView() to use the right row type based on the position (e.g., newView() inflates different row layouts based on position)

或者,你可以尝试从组装件适配器,使用像我 MergeAdapter

Or, you can try assembling your adapter from pieces, using something like my MergeAdapter.

这篇关于在Android的ListView的多种细胞类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆