在我的活动中,我实现了一个列表,其中包含一些文件的名称。每个列表项都引用了一个布局,在该布局中,我想显示图像的名称和图像缩略图。我可以使用ArrayAdapter来显示名称,但我不知道如何插入图像缩略图。所有引用的图像都存储在SD卡中,我有它们的路径。以下是单个行布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imageView"
android:layout_width="36dp"
android:layout_height="wrap_content"
android:src="@drawable/btn_nav_background_default" />
<TextView
android:id="@+id/titoloTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
活动的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/creaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Crea una nuova realtà aumentata" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Ar già create"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
以及活动代码固有适配器。
ArrayAdapter<?> arrayAdapter = new ArrayAdapter<String>(this,R.layout.row,R.id.titoloTv,targetName);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){
...................
}
});
我试图使用这个,但是它不能正常工作。
String tempTarget;
List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
for(int i = 0; i<ARelements.size();i++){
Element ar = arIterator.next();
Map<String,Object> map = new HashMap<String,Object>(2);
tempTarget = ar.getAttributeValue("TARGET");
thumbnailBitmap = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(tempTarget), THUMBSIZE, THUMBSIZE);
map.put("thumbnail", thumbnailBitmap);
map.put("titolo", tempTarget);
data.add(map);
}
arIterator= null;
SimpleAdapter simpleAdapter = new SimpleAdapter(this,data,R.layout.row,new String[] {"thumbnail","titolo"},new int[] {R.id.imageView, R.id.titoloTv});
listView.setAdapter(simpleAdapter);
getView()
方法中获取/显示图像的文本/名称... - Kody