我有一个带有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