我已将emptyView值添加到main.xml中,但当listview为空时,它不会显示任何内容。我正在使用自定义列表视图 但是,如果我只调用我的textView
listView.setEmptyView(textEmpty);
它会起作用,但我想使用布局来放置多个项目
任何人都可以帮我解决我的问题吗?提前谢谢!
我的Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_cart"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"
tools:context="com.example.gin.ordering.cart">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
></ListView>
<!-- empty view -->
<LinearLayout android:id="@+id/emptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/textEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YOUR CART IS EMPTY!"
android:textStyle="bold"
android:textColor="#000000"
android:layout_gravity="center_horizontal"
/>
</LinearLayout>
<Button
android:id="@+id/btnCheckout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CHECKOUT"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_below="@id/listView"
/>
</LinearLayout>
这是我的主要活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cart);
ListCartAdapter adapter = new ListCartAdapter(cart.this, orderid, orderName,
orderSize, orderQuantity);
listView.setAdapter(adapter);
listView.setEmptyView(findViewById(R.id.emptyView));
}
答案 0 :(得分:1)
更改您的Main.xml
ListView view = (ListView)findViewById(R.id.emptyView);
view.setEmptyView(findViewById(R.id.textEmpty));
在将适配器设置为listView之前的主要活动的OnCreate中:
In [45]: arr = np.arange(100).reshape(4, 5, 5)
In [46]: arr
Out[46]:
array([[[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]],
[[25, 26, 27, 28, 29],
[30, 31, 32, 33, 34],
[35, 36, 37, 38, 39],
[40, 41, 42, 43, 44],
[45, 46, 47, 48, 49]],
[[50, 51, 52, 53, 54],
[55, 56, 57, 58, 59],
[60, 61, 62, 63, 64],
[65, 66, 67, 68, 69],
[70, 71, 72, 73, 74]],
[[75, 76, 77, 78, 79],
[80, 81, 82, 83, 84],
[85, 86, 87, 88, 89],
[90, 91, 92, 93, 94],
[95, 96, 97, 98, 99]]])
In [51]: arr[:,:,:3] = np.round(arr[:,:,:3]/5)*5
In [52]: arr
Out[52]:
array([[[ 0, 0, 0, 3, 4],
[ 5, 5, 5, 8, 9],
[10, 10, 10, 13, 14],
[15, 15, 15, 18, 19],
[20, 20, 20, 23, 24]],
[[25, 25, 25, 28, 29],
[30, 30, 30, 33, 34],
[35, 35, 35, 38, 39],
[40, 40, 40, 43, 44],
[45, 45, 45, 48, 49]],
[[50, 50, 50, 53, 54],
[55, 55, 55, 58, 59],
[60, 60, 60, 63, 64],
[65, 65, 65, 68, 69],
[70, 70, 70, 73, 74]],
[[75, 75, 75, 78, 79],
[80, 80, 80, 83, 84],
[85, 85, 85, 88, 89],
[90, 90, 90, 93, 94],
[95, 95, 95, 98, 99]]])
如果有帮助,请告诉我
答案 1 :(得分:0)
你的意思是ListView和ListItem(EmptyView)对吗?
你需要 - ListView xml, ListItem xml, ListItem类, ArrayAdaper类