2014-06-08 131 views
0

我不断收到此错误http://prntscr.com/3qygj9(对不起,我不能复制和粘贴)从该段代码填充列表视图与一个ArrayList

final ArrayList<HashMap<String, String>> foodList = db.getAllFood(); 
    if(foodList.size() != 0){ 
     ListView listView = (ListView) findViewById(R.id.foodListView); 

     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
       this, 
       android.R.layout.simple_list_item_1, 
       foodList); 

     listView.setAdapter(arrayAdapter); 
    } 

我不能为我的生命弄清楚为什么。提前致谢!

回答

0

请您使用的是建ArrayAdapter完全不看兼容使用的ArrayAdapter<HashMap<String, String>>代替ArrayAdapter<String>

ArrayAdapter<HashMap<String, String>> arrayAdapter = new ArrayAdapter<HashMap<String, String>>(
       this, 
       android.R.layout.simple_list_item_1, 
       foodList); 
0

类型。

要构建ArrayAdapter<String>,构造函数的最后一个参数应该是ArrayList<String>类型。但在您的代码中,您为该参数传递的foodList变量的类型为ArrayList<HashMap<String, String>>