我有一个带有列表视图的android应用程序,当第一次获取数据就可以了,标题包含列表的文本,然后第二次获取数据时,执行相同的代码,标题的文本消失了。
Activity.java
LayoutInflater inflater = getLayoutInflater();
View header = (View) inflater.inflate(R.layout.header, lv, false);
header.setTag(this.getClass().getSimpleName() + "header");
if (lv.getHeaderViewsCount() > 0) {
View oldView = lv.findViewWithTag(this.getClass().getSimpleName() + "header");
if (oldView != null) {
lv.removeHeaderView(oldView);
lv.addHeaderView(header);
}
}
else
lv.addHeaderView(header);
TextView tvheader = (TextView) findViewById(R.id.tvheader);
tvheader.setText("plaplapla...");
Activity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textDirection="rtl"
android:gravity="right"
android:layout_gravity="right">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:gravity="right"
android:textAlignment="gravity"
android:textDirection="rtl"
android:layout_gravity="right"
android:background="#d9dee2">
</ListView>
</LinearLayout>
Header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text=""
android:id="@+id/tvheader"
android:background="#c0c2c4" />
</LinearLayout>
关于这个问题的任何建议
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句