Android classified listview with title

I need to display data from a database in a list. I get all the data in a group by category and displayed in a Listview. I used the following code.

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); } } 

Now I want to add the category category heading to the result set so that it looks like this:

 Categoty Fruit Apple Mango Grape Category Flower Rose Lotus Jesmine 

etc.

How can i do this? Does addHeaderView work for this? If so, how can I add it?

+5
source share
1 answer

Hey, I also had the same problem long before that. After much searching, I found this tutorial http://eshyu.wordpress.com/2010/08/15/cursoradapter-with-alphabet-indexed-section-headers/ . It worked for me.

+2
source

Source: https://habr.com/ru/post/916519/


All Articles