我有一個帶有listview的片段。該適配器只有一個字段:項目ID。Android ListView顯示空的內容
當我使用適配器將項目添加到列表中時,列表顯示項目ID。
但是,如果我把一個簡單的物品ID檢查之前(一個for-cycle檢查是否物品ID是等於一個特定的ID,如果是這樣,然後添加物品ID),列表顯示一個空行添加了一些東西),但沒有顯示項目ID。
可能是什麼?我確定「檢查部分」有效。
編輯:我忘了指定item id是一個String。
編輯2:我添加代碼的檢查部。它通過list
循環,其中包含我想要添加到其他片段列表的項目ID。 item
是我正在查看的項目。 blueF
是片段。
for(int i=0; i<list.getCount();i++) {
if(list.getItem(i).equals(item.getId())) {
//send the item to the listview of the fragment
blueF.getArrayAdapter().addItem(item);
break;
}
}
編輯3:一些測試後,我發現裏面的片段列表視圖有項目裏(我用getCount將和也被印刷在商品ID),但是它沒有顯示該項目的ID!我的自定義適配器在「add」方法中有一個notifyDataSetChanged(),並且在調用活動中的add方法之後,我也回憶起notifyDataSetChanged
...但沒有任何結果。
編輯4:可能是有些問題的佈局? 我有這樣的佈局列表行:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inventory_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/inventory_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:textSize="17sp"
android:typeface="monospace" >
</TextView>
<TextView
android:id="@+id/inventory_item_counter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="17sp"
android:typeface="monospace" />
</LinearLayout>
片段佈局列表視圖:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/listBlueTagView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</RelativeLayout>
你能告訴我們你的代碼嗎?你是否還覈實了檢查是否屬實,因此確實將該項目添加到列表中? –
張貼您的代碼請 –
抱歉,但我不能告訴你的代碼。我確定檢查是真的。我還在同一行中添加了第二個(整數)字段。適配器添加1行,將整數放入其中但不包含項目標識。 – user261591