在ExpandableListView中处理空数据视图的方法有以下几种:
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:emptyView="@+id/emptyView"/>
<TextView
android:id="@+id/emptyView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No data available"
android:visibility="gone"/>
if(data.isEmpty()){
expandableListView.setVisibility(View.GONE);
emptyView.setVisibility(View.VISIBLE);
}else{
expandableListView.setVisibility(View.VISIBLE);
emptyView.setVisibility(View.GONE);
}
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="@+id/expandableListView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include layout="@layout/empty_view"
android:id="@+id/emptyView"
android:visibility="gone"/>
</FrameLayout>
// 判断数据为空时显示EmptyView
if(data.isEmpty()){
emptyView.setVisibility(View.VISIBLE);
}else{
emptyView.setVisibility(View.GONE);
}
以上是三种常用的处理空数据视图的方法,根据实际情况选择合适的方法来处理空数据视图。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:spinner控件中如何处理空数据提示