gpt4 book ai didi

android - ListView/ExpandableListView setEmptyView() 无效

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:28:28 27 4
gpt4 key购买 nike

我正在尝试为三个 ListView 设置空 View ,即 2 个可扩展 View 和一个 ListView ,它们位于不同的选项卡中:

LayoutInflater inflater = getLayoutInflater();
View emptyView = inflater.inflate(R.layout.empty_view, null, false);
...
ExpListView1.setEmptyView(emptyView);
ListView.setEmptyView(emptyView);
ExpListView2.setEmptyView(emptyView);

它没有任何作用 - 空 View 不会出现。与该代码段相同:

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>

最佳答案

通过将空 View 作为另一个内容 View 添加到我的 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));

关于android - ListView/ExpandableListView setEmptyView() 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7400562/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com