В моем приложении мне нужно показать список миниатюр с их собственным относительным заголовком. Вот моя реализация.thumbnail simpleAdapter и текст и обработчик onItemClick
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);
Log.i("list",thumbnailBitmap.toString());
}
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);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){
List<Map<String,Object>> res = new ArrayList<Map<String,Object>>();
res = (List<Map<String, Object>>) adapter.getItemAtPosition(pos); //classCastExeption
Log.i("list","assegamento a res eseguito");
titoloriga = (String) res.get(pos).get("titolo");
Log.i("list","assegamento a titoloriga eseguito");
Log.i("list", "Ho cliccato sull'elemento con titolo" + titoloriga+" " +Integer.valueOf(pos)+" "+Long.valueOf(id));
registerForContextMenu(componente);
componente.showContextMenu();
}
});
У меня есть две проблемы: 1. Простой адаптер показать мне только заголовок, но не на миниатюру. 2. Я не знаю, как обращаться с onItemClick, мне нужно сохранить заголовок. Таким образом, у меня есть ClassCastExeption и предупреждение о ненадежности. Вот макет одной строки и списка.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="65dp"
android:layout_height="65dip"
/>
<TextView
android:id="@+id/titoloTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
и
<?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>
Спасибо-х
спасибо, что это работает. Как насчет просмотра миниатюры? – TWONEKSONE