我正在尝试为三个列表视图设置空视图,即2个可扩展视图和一个列表视图,它们位于不同的选项卡中:
LayoutInflater inflater = getLayoutInflater();
View emptyView = inflater.inflate(R.layout.empty_view, null, false);
...
ExpListView1.setEmptyView(emptyView);
ListView.setEmptyView(emptyView);
ExpListView2.setEmptyView(emptyView);
没有效果 - 不显示空视图。与该代码相同:
View emptyView = inflater.inflate(R.layout.empty_view, null, false);
View emptyRelativeLayout = (RelativeLayout) emptyView.findViewById(R.id.empty_view_layout);
ExpListView1.setEmptyView(emptyRelativeLayout);
empty_view_layout.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/empty_view_layout">
<TextView
style="@android:style/TextAppearance.Large"
android:id="@+id/empty_view_textview"
android:layout_width = "fill_parent"
android:layout_height="fill_parent"
android:text="@string/no_items_in_list"
android:layout_centerInParent="true"/>
</RelativeLayout>
答案 0 :(得分:6)
通过将空视图添加为我的Activity的另一个内容视图来解决问题:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
inflater = getLayoutInflater();
emptyView = inflater.inflate(R.layout.empty_view, null);
addContentView(emptyView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
答案 1 :(得分:1)
我这样做了:
<强> activity_main.xml中强>
var list = dbContext.Events
.Where(e => e.EndDate + e.EndTo > DateTime.Now)
.ToList();
<强> MainActivity.java 强>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/expListView">
</ExpandableListView>
<TextView
android:id="@+id/txtEmptyView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:padding="10dp"
android:text="@string/no_game_available"
android:textAppearance="@android:style/TextAppearance.Medium"
android:textColor="@android:color/white" />
</RelativeLayout>
希望这会对你有所帮助。