开发者

Android listview addHeaderView problem

开发者 https://www.devze.com 2023-02-21 02:24 出处:网络
I have to display data from the database in a listview. I have fetch all the data in alphabetical order and displayed in a Listview. I have used the following code.

I have to display data from the database in a listview. I have fetch all the data in alphabetical order and displayed in a Listview. I have used the following code.

private ListView infos;


@Override
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(saved开发者_运维问答InstanceState);
  .........
  .........
  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);
   }

}

Now I want to add heading A-Z on result set so that it looks like that-

A
Apple
Android
Ass
B
Ball
Bolt

and so on..

How can I make it? Does the addHeaderView work for it? If it is, How I can add it?


For this we are having AlphabetIndexer that seperate lists values by alphabetic order..

Check this link Alphabetic Indexer....

0

精彩评论

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