LinkAdapter
是一个扩展ArrayAdapter
.
private static List<LinkData> linkDataList = new ArrayList<LinkData>();
private LinkAdapter la;
la = new LinkAdapter(someLinkDataitmes, getActivity());
ListView lv = (ListView) v.findViewById(R.id.urls);
lv.setAdapter(la);
public class LinkData {
private String name, image, description;
public LinkData(String name, String image, String description){
this.name = name;
this.image=image;
this.description=description;
}
}
现在我稍后想更新我的listview
,
ListView lv = (ListView) v.findViewById(R.id.urls);
LinkAdapter mListAdapter = ((LinkAdapter)lv.getAdapter()); // this line is giving an error.
mListAdapter.add(new LinkData(name_val, image_val, description_val));
mListAdapter.notifyDataSetChanged();
但是代码不起作用(给出一个NullPointerException
)
在互联网上搜索了很多,但找不到我的问题的具体答案。