设置文本在ListActivity一个TextView [英] Setting text for a TextView in ListActivity
本文介绍了设置文本在ListActivity一个TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过扩展ListActivity填充列表。我添加了一个头列表以显示列表中的项目的总数。
我都保持在一个单独的布局文件header.xml标题视图,如下所示。
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT>
<的TextView
机器人:ID =@ + ID / headerTextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=设备总数
机器人:TEXTSIZE =15dip
机器人:layout_weight =1/>
< / LinearLayout中>
这是怎么了添加标题在ListViewActivity类名单,
的ListView LV = getListView();
LayoutInflater吹气= getLayoutInflater();
ViewGroup中头=(ViewGroup中)inflater.inflate(R.layout.header,LV,假);
lv.addHeaderView(头,空,假);
我设置了标题TextView的文本怎么办?我试过以下,它的TextView中返回null。
的TextView的textBox =(的TextView)findViewById(R.id);
textBox.setText(计数);
解决方案
试试这个
查看标题=(查看)inflater.inflate(R.layout.header,LV,假);
lv.addHeaderView(头,空,假);
让你的TextView在头文件
的TextView的textBox =(TextView中)header.findViewById(R.id.headerTextView);
I am populating a list by extending ListActivity . I have added a header to the list to show the total count of items in the list.
I have maintained the header view in a separate layout file header.xml as shown below.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/headerTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Total number of devices :"
android:textSize="15dip"
android:layout_weight="1" />
</LinearLayout>
This is how I am adding header to the list in the ListViewActivity class,
ListView lv = getListView();
LayoutInflater inflater = getLayoutInflater();
ViewGroup header = (ViewGroup)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
How do I set the text for the header TextView? I tried the following and it returned null for the TextView.
TextView textBox = (TextView)findViewById(R.id.);
textBox.setText("Count");
解决方案
Try this
View header = (View)inflater.inflate(R.layout.header, lv, false);
lv.addHeaderView(header, null, false);
Get your TextView in header
TextView textBox = (TextView)header.findViewById(R.id.headerTextView);
这篇关于设置文本在ListActivity一个TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文