简体   繁体   English

如何在列表视图中添加顶部项目?

[英]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.基本上我想要一个列表视图(CheckBox 和 TextView),它包含数据库中的所有数据,但视图中的第一项始终是“ALL”。我已经加载了 listadapter,但我不知道如何将第一行添加为 All . If I am clicking All checkebox.I want to other checkbox's state as false.如果我单击所有复选框。我希望其他复选框的状态为 false。 my code as follow..我的代码如下..

you can add HeaderView in ListView您可以在ListView 中添加HeaderView

here is simple code of How to add HeaderView in ListView.这是如何在 ListView 中添加 HeaderView 的简单代码

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.创建headerview.xml ,您可以在此布局中添加带有“ALL”文本的TextView

Why don't you do it like this?你为什么不这样做呢?

You get position in getview() , then for the first item add condition.您在getview()获得位置,然后为第一项添加条件。 Something like this:像这样的东西:

if(position == 0)


    youTextView.setText("All");

That's it.而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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