您的位置:首页 > 移动开发 > Android开发

Android ListView SimpleAdapter ArrayList 数据更新问题

2013-09-12 21:31 826 查看
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.clear(); //或者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()就可以
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐