2014-03-07 75 views
1

ArrayList<HashMap<String, ?>> list; 
f(!list.isEmpty()){ 

      adapter = new MySimpleArrayAdapter(getActivity(),R.layout.inner_base_header_cutom, list); 
      listview.setAdapter(adapter); 
      Log.i("LIST Active", "LIST Active" + list.size()); 
     } 

public class MySimpleArrayAdapter extends ArrayAdapter<ArrayList<HashMap<String, ?>>> { 
      private final Context context; 
      private final ArrayList<HashMap<String, ?>> values; 

      public MySimpleArrayAdapter(Context context, int innerBaseHeaderCutom, ArrayList<HashMap<String, ?>> list) { 
      super(context, innerBaseHeaderCutom, list); 
      this.context = context; 
      this.values = list; 
      } 

}不能與ArrayList中填充的ListView <HashMap的<String,?> >>


錯誤:

The constructor ArrayAdapter<ArrayList<HashMap<String,?>>>(Context, int, ArrayList<HashMap<String,?>>) is undefined 

而且無法刪除的ListView:

remove(list.get(position)); 

錯誤:
另一種認爲你可以嘗試是:

The method remove(ArrayList<HashMap<String,?>>) in the type ArrayAdapter<ArrayList<HashMap<String,?>>> is not applicable for the arguments (HashMap<String,capture#2-of ?>) 
+0

什麼是名單在你的代碼? – Raghunandan

+0

'ArrayList >',我在上面添加了一些。 – rahstame

+0

'ArrayList > list'爲什麼是'?'。他們的價值不是一個字符串?另外你在哪裏填充列表 – Raghunandan

回答

1

,當你調用超類

super(context, innerBaseHeaderCutom); 

編輯的構造就剝奪的最後一個參數改變這一點:

public class MySimpleArrayAdapter extends ArrayAdapter<ArrayList<HashMap<String, ?>>> { 

public class MySimpleArrayAdapter extends ArrayAdapter<HashMap<String, ?>> { 

,做在構造函數中相同的變化。

+0

適配器如何知道許多列表應填充先生。仍然沒有填充我檢查'list.size',我得到了三個。 – rahstame

+0

查看編輯答案 – Merlevede

+0

該代碼幫助我!!!!!爲什麼我們需要省略ArrayList?謝謝 – rahstame

0
You are creating ArrayList with ArrayList<HashMap<String, ?>> instead you can try ArrayList<HashMap<String, ? extends Object>> 

檢查示例代碼和輸出。

public class MyJavaTesting{ 
public MyJavaTesting(ArrayList<HashMap<String, ? extends Object>> list) { 
    System.out.println(list); 
} 

public static void main(String[] args) { 
    ArrayList<HashMap<String, ? extends Object>> list = new ArrayList<HashMap<String,?>>(); 
    HashMap<String, String> map1 = new HashMap<String, String>(); 
    map1.put("Key", "value"); 
    list.add(map1); 

    HashMap<String, Object> map2 = new HashMap<String, Object>(); 
    map2.put("Key", new Object()); 
    list.add(map2); 

    MyJavaTesting manager = new MyJavaTesting(list); 
} 
} 

輸出: [{鍵=值},{[email protected]}]

相關問題