1

これに関して多くの解決策がありますが、どれも私の問題を解決しませんでした。私がやりたいことは、私のリストビューが空のとき、デフォルトの空のテキストビュー(xmlで宣言されている)が表示されればOKですが、listfragmentを拡張するアクティビティのある時点でそのテキストを変更したい場合はどうすればよいですか私の必要性とそれを見えるようにする....最近私はこれを試しました:

public void setEmptyText(CharSequence emptyText) {
    ListView mListView = (ListView) NotificationsView.findViewById(android.R.id.list);
    View emptyView = mListView.getEmptyView();
        ((TextView) emptyView).setText(emptyText);
}

エラーは発生しませんが、問題も解決していません。どんな助けでも感謝します

編集: これがリストフラグメントの私のレイアウトです

     <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="MergeRootFrame" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_vertical|center_horizontal"
        android:orientation="vertical" >

        <ListView
            android:id="@id/android:list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/fragment_bg"
            android:divider="@null"
            android:dividerHeight="1dp"
            android:listSelector="@drawable/list_style" >
        </ListView>

        <TextView
            android:id="@id/android:empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/fragment_bg"
            android:text="No data" />
    </LinearLayout>

</android.support.v4.widget.SwipeRefreshLayout>
4

3 に答える 3

0

デフォルトでは、リストビューまたはアダプター (どちらを覚えていないか) によって非表示になります。呼び出しemptyView.setVisibility(View.VISIBLE);て表示します。

于 2015-02-11T14:49:51.813 に答える
0

これは、テキスト ビューの値を変更する方法です。

TextView tv = (TextView) findViewById(R.id.empty);
tv.setText('yourText');
于 2015-02-11T14:50:03.367 に答える