【问题标题】:How to set list view with array?如何使用数组设置列表视图?
【发布时间】:2016-05-11 18:33:07
【问题描述】:

我在设置列表视图时遇到问题, 当我创建数组并尝试放入列表视图时,返回错误无法解析构造函数 ArrayAdapter 这是我的数组。

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.xml_busqueda_proveedores);


ArrayList<HashMap<String, String>> arl = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("lista");

System.out.println("::: array " + arl); 
// This is the array
// ::: array [{1=111, 2= LOCAL }, {1=12, 2= CIUDAD}, {}, {}, {}]

list = (ListView)findViewById(R.id.ListProveedores);

ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arl);
//Error Cannot resolve constructor ArrayAdapter
list.setAdapter(adaptador);
}

【问题讨论】:

标签: android listview android-arrayadapter


【解决方案1】:

你的问题是因为你创建了一个 String 的 ArrayAdapter,但是你给你的适配器一个 ArrayList 的 HashMap 的两个字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-24
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 2011-10-20
    相关资源
    最近更新 更多