为什么我的ListView没有显示我的项目?

3

我有一个列表视图,想要显示多个项目。然而,在编译程序后,什么也没有显示出来,我不确定原因所在。

    ListView listView = findViewById(R.id.quikList);
    ArrayList<String> list = new ArrayList<String>();

    list.add("Hello");
    list.add("Is it me youre looking for?");
    list.add("I can see it in your smile and I want so badly to make this listview work");

    ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, list);
listview.setAdapter(aa);

我不知道为什么这个很基本的任务不能正常工作。我认为可能是因为 android.R.id.text1,但我不确定原因。任何人能在这个话题上提供帮助就太好了。


一个更新:这个列表肯定已经存储了项目。我用logcat检查过了。 - Jerg
为什么不使用RecyclerView? - DennisVA
1
尝试使用具有3个参数的构造函数,而不使用TextViewResId:https://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,%20int,%20T[]) - Bruno
2个回答

1
不需要第三个参数,只需删除此行 android.R.id.text1
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, list);
listView.setAdapter(aa);

解决方案2:

可能是您的主题问题,这意味着您的Textview颜色与Listview背景颜色相同。

因此只需更改您的listview背景颜色即可...

android:background="@android:color/holo_red_dark"

哈哈,是解决方案2...我讨厌自己。 - Jerg

1

Try this:

ListView listView = (Listview)findViewById(R.id.quikList);

String list[] = {"Hello","Is it me youre looking for?","I can see it in your smile and I want so badly to make this listview work"};   

ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.simple_list_item_1, R.id.textView, list);

listview.setAdapter(aa);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接