简体   繁体   中英

How to add top item in list view?

Basically I want a list view(CheckBox and TextView) that has all the data from a database but the first item in the view always being "ALL".I have done loading listadapter but i don't know how to add first row as All. If I am clicking All checkebox.I want to other checkbox's state as false. my code as follow..

you can add HeaderView in ListView

here is simple code of How to add HeaderView in ListView.

LayoutInflater inflater = getLayoutInflater();
LinearLayout listHeaderView = (LinearLayout)inflater.inflate(
                R.layout.headerview, null);
ListView.addHeaderView(listHeaderView);

create headerview.xml and you can add in this layout TextView with "ALL" text.

Why don't you do it like this?

You get position in getview() , then for the first item add condition. Something like this:

if(position == 0)


    youTextView.setText("All");

That's it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM