0

내 앱에서 썸네일 목록을 상대적인 제목과 함께 표시해야합니다. 내 구현은 다음과 같습니다. 1. 간단한 어댑터가 나에게 제목 만이 아니라 썸네일을 보여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(); 

      } 

    }); 

나는 두 가지 문제가있다. 2. onItemClick을 처리하는 방법을 모르겠습니다. 제목을 저장해야합니다. 이 방법으로 나는 ClassCastExeption과 unsafe 캐스팅에 대한 경고를받습니다. 다음은 단일 행과 listview의 레이아웃입니다.

<?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> 

감사의

답변

0

의 ListView의 항목 클릭에, 당신은 당신이 얻을 수있는 다시 해시 맵의 ArrayList를 만들 필요가 없습니다하는 해시 맵의 당신의 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(); 

     } 

}); 
+0

고맙다. 미리보기 이미지보기는 어떻습니까? – TWONEKSONE