1

私は ListView を使用しており、リストが空の場合は EmptyView を表示します。このビューがブール変数で表示されているかどうかを確認するにはどうすればよいですか?

ここに私のListViewのコード:

deviceList = (ListView) findViewById(R.id.DeviceList);
ListAdapter listenAdapter = new ArrayAdapter(this,
                android.R.layout.simple_list_item_2, deviceArray);

//add a view which is shown if the ListView is empty
deviceList.setEmptyView( findViewById( R.id.empty_list_view ) );
deviceList.setAdapter(listenAdapter);
4

1 に答える 1

0

「特別な」Android IDを使用して、xmlでこれを行うことができます。レイアウト xml ファイルでこのコードを使用すると、必要に応じて空のテキストが自動的に表示されます。

<ListView android:layout_height="wrap_content" android:layout_width="match_parent"    android:id="@id/android:list"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent"   android:text="@string/no_tasks" android:id="@id/android:empty"
android:gravity="center_vertical|center_horizontal"/>

android:empty id の textview は、android:list コンポーネントが空の場合にのみ表示されます。

それが役立つことを願っています。

于 2012-10-22T17:31:27.827 に答える