从 ListAdapter 编辑 TextView?
我有一个 ListView,它由 ArrayAdapter 支持。它们的定义如下:
ListView listView = (ListView)findViewById(R.id.listview);
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, R.layout.list_item);
listView.setAdapter(listAdapter);
list_item.xml 包含以下内容:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
将项目添加到列表时我想要做的是编辑与该项目关联的 TextView,例如更改其颜色。我该怎么做呢?
I have a ListView, which is backed by an ArrayAdapter. They are defined as such:
ListView listView = (ListView)findViewById(R.id.listview);
ArrayAdapter<String> listAdapter = new ArrayAdapter<String>(this, R.layout.list_item);
listView.setAdapter(listAdapter);
list_item.xml contains the following:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp"
android:textSize="16sp">
</TextView>
What I would like to do when adding an item to the list, is edit the TextView associated with the item, like changing it's colour for example. How would I go about doing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以重写 ArrayAdapter 的方法
getView()
(参考链接)例如:You could override the method
getView()
of your ArrayAdapter (link to the reference) for example:您应该去看这个 Google I/O 演讲: http://www.google.com/events/io/2010/sessions/world-of-listview-android.html 它解释了 ListView 的基础知识以及如何去做这些事情。
You should go watch this Google I/O talk: http://www.google.com/events/io/2010/sessions/world-of-listview-android.html it explains the basics of ListView and how you would go about doing these sorts of things.