2016-03-22 4 views
0

'daki HashMap konumunu alamıyorum HashMap için özel bir adaptör yaptım, sorun, CustomAdapter ile TextView for HashMap'i ayarlayamıyorum. ikinci son satır, HashMap konumu elde etmek için hatası alıyor. Lütfen sözdizimi hatasının nasıl çözüleceğine ve CustomAdapter ayarlanmasına yardımcı olun., CustomAdapter

CustomAdapter.java

public class CustomAdapter extends ArrayAdapter<HashMap<String, Object>> { 

     private SparseBooleanArray mSelectedItemsIds; 
     private LayoutInflater inflater; 
     private Context mContext; 
     private List<HashMap<String, Object>> list; 
     Blocklist blocklist; 

     public CustomAdapter (Context context, int resourceId, List<HashMap<String, Object>> list) { 
      super(context, resourceId, list); 
      mSelectedItemsIds = new SparseBooleanArray(); 
      mContext = context; 
      inflater = LayoutInflater.from(mContext); 
      this.list = list; 
     } 

     private static class ViewHolder { 
      TextView itemName; 
     } 

     public View getView(int position, View view, ViewGroup parent) { 
      final ViewHolder holder; 
      if (view == null) { 
       holder = new ViewHolder(); 
       view = inflater.inflate(R.layout.custom_textview, null); 
       view = inflater.inflate(R.layout.custom_textview, null); 
       holder.itemName = (TextView) view.findViewById(R.id.custom_tv); 
       view.setTag(holder); 
      } else { 
       holder = (ViewHolder) view.getTag(); 
      } 

      holder.itemName.setText(list.get(position)); 
      return view; 
     } 

Blocklist.java

HashMap<String,Object> hm = new HashMap<String,Object>(); 
       hm.put(ID, cursor.getLong(0)); 
       hm.put(ORIGINATING_ADDRESS, cursor.getString(1)); 
       hm.put(MESSAGE_BODY, cursor.getString(2)); 
       arrayList.add(hm); 
       cursor.moveToNext(); 
+0

hata günlüğüne ekleyin. –

+0

Neden getView'de 2 kez yanıltıcı. –

+0

yanlışlıkla @jaydroider –

cevap

2

Şu ana kadar:

holder.itemName.setText(list.get(position)); 

yukarıdaki satır bir HashMap nesnesi list.get(position) sonuçları olarak çalışmaya ve bir olmaz dize nesnesi. Eğer fro örnek MESSAGE_BODY göstermek istiyorsanız da sen

view = inflater.inflate(R.layout.custom_textview, null); 

twice`

+0

'a teşekkürler –

0
list.get(position) 

dönüş nesnesi HashMap şişirmek gerekmez bu

holder.itemName.setText((String)list.get(position).get(MESSAGE_BODY)); 

gibi kullanmalıdır position, String

İlgili konular