在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);
}
以上是三種常用的處理空數據視圖的方法,根據實際情況選擇合適的方法來處理空數據視圖。