如何使用ArrayAdapter来显示一个列表视图?视图、如何使用、列表、ArrayAdapter

2023-09-06 22:00:44 作者:心碎志不可碎

您好我想显示在我的应用程序的列表视图。应的每一行包含一个文本和图像。我用ArrayAdapter来显示这一点,但如何将文本后插入一个图像。

Hi i want to display a list view in my application. Each row should contains a text and an image. I have used ArrayAdapter to display this, but how to insert an image after the text.

String lvr[]={"Android","iPhone","BlackBerry","AndroidPeople"};
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list1 = (ListView) findViewById(R.id.cg_listview1);
list1.setAdapter(new ArrayAdapter<String>(this,R.layout.alerts , lvr));

下面警报是我的布局中只包含TextView的。

Here alerts is my layout contains only textView.

推荐答案

如果你想有过项目的布局如何看待在列表视图控件,你应该做的 ArrayAdapter

If you want to have control over how the layout of items look in a list view, you should make your own custom implementation of ArrayAdapter:

这是管理一个ListView一个ListAdapter  由任意数组支持  对象。 (......)要使用其他的东西  比TextViews为阵显示器,  例如,ImageViews,或有  除了一些数据的toString()的  结果填补意见,覆盖  getView(INT,查看,ViewGroup中),以  返回所需的视图类型。

A ListAdapter that manages a ListView backed by an array of arbitrary objects. (...) To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

如果你只是谷歌定制arrayadapter例如,你应该找足够的例子向您展示如何实现这一点。两个这样的例子是:

If you just google for custom arrayadapter example, you should find enough examples showing you how to implement this. Two such examples are:

的http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/的http://android-er.blogspot.com/2010/06/custom-arrayadapter-with-with-different.html

祝你好运:)