我有一个包含不同项目的活动,其中一个项目是ListView。 我创建了一个自定义列表适配器并发送给它一个json数组。 列表的数据来自服务器。评论Android中的列表视图
列表的目的是作出评论列表。我允许用户插入 评论,然后我在ListView中显示它。 当我有一些项目在列表中的作品,并显示项目。 问题是当列表视图为空并且用户发表评论时。 我看到数据已更改,但没有看到该项目,表示该列表未更新。
因此,我尝试向列表视图添加空视图,但它不起作用。
这里是一个更新的代码:(UPDATE)
if (!s.isEmpty() && !s.equals("{}")) {
try {
if (commentsListAdapter == null) {
commentsList.setEmptyView(findViewById(R.id.dummy));
commentsListAdapter = new CommentsListAdapter(PostView.this);
}
JSONObject resObj = new JSONObject(s);
list.add(resObj);
commentsListAdapter.setDataSet(list);
cmntTxt.setText("");
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
commentCounter.setText(Integer.toString(list.size()));
} catch (JSONException e) {
e.printStackTrace();
}
}
和适配器里面我有这样的功能:
public void setDataSet(List<JSONObject> list){
commentsList = list;
notifyDataSetChanged();
}
但问题是不固定的..
listview.setAdapter()的代码在哪里?也许在这个方法或Activity中发布更多的代码。 –