Android listview addHeaderView问题

时间:2011-04-01 13:27:13

标签: android listview header add

我必须在列表视图中显示数据库中的数据。我按字母顺序获取所有数据并显示在Listview中。我使用了以下代码。

private ListView infos;


@Override
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  .........
  .........
  infos = new ListView(this);
  model = infoDataHelper.getCursor(addType);
  adapter = new InfoAdapter(model);
  infos.setAdapter(adapter);
  .........
  .........
}


class InfoAdapter extends CursorAdapter {

  public InfoAdapter(Cursor c) {
    super(getParent(), c);
    // TODO Auto-generated constructor stub
  }

  @Override
   public void bindView(View row, Context ctxt, Cursor c) {
    InfoHolder holder = (InfoHolder) row.getTag();
    holder.populateTable(c, infoDataHelper);
   }

   @Override
   public View newView(Context ctxt, Cursor c, ViewGroup parent) {

    LayoutInflater inflater = getLayoutInflater();

    View row;
        row = inflater.inflate(R.layout.inforow, parent, false);

    InfoHolder holder = new InfoHolder(row);
    row.setTag(holder);
    table_id++;
    return (row);
   }

}

现在我想在结果集上添加标题A-Z,使其看起来像那样 -

A
Apple
Android
Ass
B
Ball
Bolt

依旧......

我该怎么做? addHeaderView是否有效?如果是,我如何添加它?

1 个答案:

答案 0 :(得分:1)

为此,我们使用AlphabetIndexer按字母顺序分隔列表值。

点击此链接Alphabetic Indexer ....