Android ListView SimpleAdapter ArrayList 数据更新问题 zhuan
16lz
2021-01-23
Android ListView SimpleAdapter ArrayList 数据更新问题
2011-05-24 18:52
private GridView myListView;
private SimpleAdapter mySimperAdapter;
private ArrayList<HashMap<String, Object>> myData;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.position);
arrayList = new ArrayList<HashMap<String, Object>>(); //只能初始化一次 否者改变不了
}
public void SetData()
{
arrayList.removeAll(arrayList);
for(){
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("1", "");
hashMap.put("2", "");
arrayList.add(hashMap);
}
}
private void Init()
{
mySimperAdapter = new SimpleAdapter(this, arrayList,
R.layout.main, new String[] {"1", "2"}, new int[]{R.id.li1, R.id.li2});
myListView.setAdapter(mySimperAdapter);
}
修改myData的数据以后,调用mySimpleAdapter.notifyDataChanged()就可以
2011-05-24 18:52
private GridView myListView;
private SimpleAdapter mySimperAdapter;
private ArrayList<HashMap<String, Object>> myData;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.position);
arrayList = new ArrayList<HashMap<String, Object>>(); //只能初始化一次 否者改变不了
}
public void SetData()
{
arrayList.removeAll(arrayList);
for(){
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("1", "");
hashMap.put("2", "");
arrayList.add(hashMap);
}
}
private void Init()
{
mySimperAdapter = new SimpleAdapter(this, arrayList,
R.layout.main, new String[] {"1", "2"}, new int[]{R.id.li1, R.id.li2});
myListView.setAdapter(mySimperAdapter);
}
修改myData的数据以后,调用mySimpleAdapter.notifyDataChanged()就可以
更多相关文章
- Android音频口数据通信开发;通过静态分析工具了解IPA实现 -- iOS/
- WebView之js调用Android类的方法传递数据 - 依凡王子
- Android 实现json网络数据通过BaseAdapter加载到ListView中
- Android中有关数据库SQLite的介绍
- Android使用HttpURLConnection和HttpClient请求服务器数据
- Android应用程序的数据存放目录 路径
- 一步一步学习androidNDK编程(java给c传递数据)