如何自动将图像缩略图添加到列表视图?
我的目标是在每个列表视图条目中添加缩略图。当程序打开时,它将图像下载到 SD 卡。我怎样才能使列表视图上的第一个条目具有 image1 的缩略图,第二个条目自动获取缩略图 image2 等。我需要以编程方式完成此操作,因为我有一个包含 1200 多个选项的菜单,所有选项都带有相应的图像。我已经修改了 R.layout.itemlayout 文件,以便它具有图像视图,我只是不确定如何根据图像视图在列表视图中的位置以编程方式更改图像视图的源。提前致谢!
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Chapter0Menu extends ListActivity {
private static final String TAG = null;
public static String url;
public static String[] fileArray;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String[] chapter0Array = getResources().getStringArray(R.array.chapter0);
setListAdapter(new ArrayAdapter<String>(Chapter0Menu.this, R.layout.itemlayout, chapter0Array));
}
My goal is to add a thumbnail image in each of the listview entries. When the program opens, it downloads the images to the sd card. How can I make it so that the first entry on the listview has the thumbnail of image1 and the second entry automatically gets thumbnail image2, etc etc. I need this to be programmatically done since I have a menu of 1200+ options all with corresonding images. I have modified the R.layout.itemlayout file so that it has an imageview, I'm just not sure how to programmatically change the source of the imageview based on its position within the listview. Thanks in advance!
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Chapter0Menu extends ListActivity {
private static final String TAG = null;
public static String url;
public static String[] fileArray;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
String[] chapter0Array = getResources().getStringArray(R.array.chapter0);
setListAdapter(new ArrayAdapter<String>(Chapter0Menu.this, R.layout.itemlayout, chapter0Array));
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该必须使用 customListAdapter 来完成此列表视图,以显示多个图像和您想要的内容。
请参阅 这个例子。在这个例子中有多个textview。在这里,您可以使用图像视图来代替文本视图来显示您想要的图像。
希望它能帮助你。
谢谢。
You should have to use the customListAdapter to done this List view for display the multiple Images and what ever you want.
See this example. in this example there are multiple textview. Here instead of the text view you can take the Image view to show the Image you want.
Hope it will help you.
Thanks.
我刚刚分享了我的个人课程,将下载队列中的图像下载到您的 SD 卡上。请尝试使用它并告诉我它是否是您正在寻找的内容:
http://code.google .com/p/imagemanager/
I just shared my personal class to dowload images in a download queue to you sd-card. Please try to use it and tell me if it's what you're looking for:
http://code.google.com/p/imagemanager/