ListView で SherlockListActivity を使用しています。リストに項目がない場合、no_data 文字列を表示したいと思います。@android:id/empty を使用していくつかの例に従いましたが、うまくいきません。「空の」テキスト ビューは表示されません。どんな助けでも大歓迎です。これは私のlayout.xmlです:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ListView android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@android:id/empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/no_data"/>
</LinearLayout>
これは、リストビューが MainActivity Java ファイルに入力される方法です
private void fillData()
{
// Get cursor of name, bal, date for account list
Cursor cursor = db.getCursor();
startManagingCursor(cursor);
// THE DESIRED COLUMNS TO BE BOUND
String[] columns = new String[] { "accounts.name", "accounts.bal", "accounts.ot"};
// THE XML DEFINED VIEWS WHICH THE DATA WILL BE BOUND TO
int[] to = new int[] { R.id.tvName,R.id.tvBal, R.id.tvDate };
// CREATE THE ADAPTER USING THE CURSOR POINTING TO THE DESIRED DATA AS WELL AS THE LAYOUT INFORMATION
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, R.layout.main_list_item, cursor, columns, to);
// SET THIS ADAPTER AS YOUR LISTACTIVITY'S ADAPTER
this.setListAdapter(mAdapter);
}
これは、別のJavaクラスでカーソルを作成する方法です
// Getting All accounts
public Cursor getCursor() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ACCOUNTS, new String[] {
KEY_AID, // Account ID Integer
KEY_NAME, // Name of account
KEY_BAL, // Balance
KEY_ADATE, // Occurrence time
},
KEY_TYPE + "=?",
new String[] {"2"}, null, null, null);
// return account list
return cursor;