【发布时间】:2017-05-09 08:48:41
【问题描述】:
我已将 emptyView 值添加到 main.xml,但当列表视图为空时,它不会显示任何内容。我正在使用自定义列表视图 但是如果我只像这样调用我的 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));
}
【问题讨论】:
-
@VikasTiwari 好吧,先生,我已经尝试过这个特定的答案,问题是它不起作用先生。这就是我发布这个问题的原因,以便某些人可以提供帮助。先生,您对我的问题有意见吗?
-
@Lingeshwaran 好吧,先生,我已经尝试过这个特定的答案,问题是它不起作用先生。这就是我发布这个问题的原因,以便某些人可以提供帮助。先生,您对我的问题有意见吗?
-
发布完整的 Main.xml
标签: android