Android 带有图像和文本的 ListView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2580170/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ListView with images and text
提问by rui pinheiro
What's the way to create a listview with images on the left side and text right after it? (Note: the images were previously downloaded from the Net) Thanks in advance!
用左边的图像和后面的文本创建列表视图的方法是什么?(注:图片是之前从网上下载的)先谢谢了!
回答by Fedor
Here's a complete sample code Lazy load of images in ListView. You can reuse it.
这是一个完整的示例代码ListView 中的图像延迟加载。你可以重复使用它。
If you have new items in the list you just call adapter.notifyDatasetChanged()
and ListView
will redisplay all items including the new ones.
如果列表中有新项目,您只需调用adapter.notifyDatasetChanged()
并ListView
重新显示包括新项目在内的所有项目。
The getView()
method in adapter inflates item.xml and displays real data in it. You need to start with some basic ListView
tutorial, such as the one at Android Series: Custom ListView items and adapters.
getView()
适配器中的方法膨胀 item.xml 并显示其中的真实数据。您需要从一些基本ListView
教程开始,例如Android 系列中的教程:自定义 ListView 项和适配器。
回答by Robby Pond
A ListView item can have it's own custom layout. When you create your adapter for the ListView you can pass in the layout id to the Adapter constructor. See SimpleAdapterand ArrayAdapter.
ListView 项可以有自己的自定义布局。当您为 ListView 创建适配器时,您可以将布局 ID 传递给 Adapter 构造函数。请参阅SimpleAdapter和ArrayAdapter。
=> You will have to extend an Adapter and implement getView()
to property set the image+text.
=> 您必须扩展适配器并实现getView()
图像+文本的属性设置。
回答by Jabbir Basha
Hi this class is used to make the image to bind with list view use simple adater and use the following class
嗨这个类用于使图像与列表视图绑定使用简单的适配器并使用以下类
class MyViewBinder implements ViewBinder {
public boolean setViewValue(View view, Object data,String textRepresentation) {
if( (view instanceof ImageView) & (data instanceof Bitmap) ) {
ImageView iv = (ImageView) view;
Bitmap bm = (Bitmap) data;
iv.setImageBitmap(bm);
return true;
}
return false;
}
}