Android simpleAdapter缩略图和文本以及单击处理程序

Android simpleAdapter缩略图和文本以及单击处理程序,android,classcastexception,onitemclicklistener,simpleadapter,Android,Classcastexception,Onitemclicklistener,Simpleadapter,在我的应用程序中,我需要显示一个缩略图列表和它们自己的相对标题。 这是我的实现 String tempTarget; List<Map<String,Object>> data = new ArrayList<Map<String,Object>>(); for(int i = 0; i<ARelements.size();i++){ Element ar = arIterator.next();

在我的应用程序中,我需要显示一个缩略图列表和它们自己的相对标题。 这是我的实现

    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();

           } 

    }); 
字符串目标;
列表数据=新的ArrayList();
对于(int i=0;i



谢谢

在ListView的项目点击上,您不需要再次创建哈希映射arraylist,您可以通过它获得存储在hashmap的arraylist中的哈希映射。因此,请更改

   listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
       @Override  
       public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){  

           String title = data.get(pos).get("titolo");
           String thumbimage = data.get(pos).get("thumbnail");
           registerForContextMenu(componente);
           componente.showContextMenu();

       } 

}); 
listView.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView适配器,最终视图组件,int pos,long id){
字符串标题=data.get(pos.get)(“titolo”);
字符串thumbimage=data.get(pos.get(“缩略图”);
registerForContextMenu(组件);
showContextMenu();
} 
}); 

thank's it’s works.缩略图的视图如何?
<?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>
   listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
       @Override  
       public void onItemClick(AdapterView<?> adapter, final View componente, int pos, long id){  

           String title = data.get(pos).get("titolo");
           String thumbimage = data.get(pos).get("thumbnail");
           registerForContextMenu(componente);
           componente.showContextMenu();

       } 

});