gpt4 book ai didi

c - 如何让Listview不可选?

转载 作者:行者123 更新时间:2023-11-30 17:17:41 25 4
gpt4 key购买 nike

我使用DialogBox创建了一个应用程序。我向其中添加了一个 ListView

有没有办法让这个Listview不可选择?

用户不应该选择任何内容,它应该只显示一些数据。

提前致谢!

最佳答案

为了在列表创建时禁用列表项,您必须从 ArrayAdapter 进行子类化。您必须重写以下方法:isEnabled(intposition) 和 areAllItemsEnabled()。在前者中,您返回 true 或 false,具体取决于给定位置的列表项是否启用。在后者中你返回 false。

如果您想使用 createFromResource(),您也必须实现该方法,因为 ArrayAdapter.createFromResource() 仍然实例化 ArrayAdapter 而不是您自己的适配器。

最后,代码如下所示:

class MenuAdapter extends ArrayAdapter<CharSequence> {

public MenuAdapter(
Context context, int textViewResId, CharSequence[] strings) {
super(context, textViewResId, strings);
}

public static MenuAdapter createFromResource(
Context context, int textArrayResId, int textViewResId) {

Resources resources = context.getResources();
CharSequence[] strings = resources.getTextArray(textArrayResId);

return new MenuAdapter(context, textViewResId, strings);
}

public boolean areAllItemsEnabled() {
return false;
}

public boolean isEnabled(int position) {
// return false if position == position you want to disable
}

}

关于c - 如何让Listview不可选?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29374302/

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