Android listview标题文本在刷新listview时消失

Android listview标题文本在刷新listview时消失,android,listview,text,header,Android,Listview,Text,Header,我有一个android应用程序,带有列表视图,当第一次获取数据时,标题中包含列表文本,ok 然后,当第二次获取数据时,执行相同的代码,并且头的文本消失 Activity.java LayoutInflater inflater = getLayoutInflater(); View header = (View) inflater.inflate(R.layout.header, lv, false); header.setTag(this.get

我有一个android应用程序,带有列表视图,当第一次获取数据时,标题中包含列表文本,ok 然后,当第二次获取数据时,执行相同的代码,并且头的文本消失

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>
<?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>

Header.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>
<?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>


对于该问题的任何建议

解决方案是在findviewbyid中获得特定位置:

TextView tvheader = (TextView) header.findViewById(R.id.tvheader);

感谢来自组的回复

请参见此处:它的stickylistheaders不是我需要的它看起来像你是oldview是空的。检查你得到它的方式。我想这就是问题所在。也可以考虑将块放入其他,虽然它对于单个语句是可选的,但它会增加可读性!你有什么错误吗?@Xenolion没有任何错误