我正在使用android 这是我的代码:
public void done(List<ParseObject> colList, ParseException e) {
if (e == null) {
dataList = new ArrayList<String>();
for(int counter = 0; counter < colList.size(); counter++)
{
String data = colList.get(counter).getString("name");
dataList.add(data);
}
listAdapter = new ArrayAdapter<String>(WardRobeActivity.this,
android.R.layout.simple_list_item_1,dataList);
ListView listview = (ListView)findViewById(R.id.listView);
listview.setAdapter(listAdapter);
} else {
Log.d("score", "Error: " + e.getMessage());
}
我从云端获取数据。 colList有来自云的数据列表,我将它添加到arrayList然后将它设置为listView适配器我的代码有什么问题?
答案 0 :(得分:0)
首先创建listAdapter并添加data
。
[...]
listAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);
ListView listview = (ListView)findViewById(R.id.listView);
listview.setAdapter(listAdapter);
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
listAdapter.add(String.valueOf(colList.size())); //only a Test
for(int counter = 0; counter < colList.size(); counter++)
{
String data = colList.get(counter).getString("name");
if (data == "")
{
listAdapter.add("no name");
} else {
listAdapter.add(data);
}
}
listAdapter.notifyDataSetChanged();
[...]