Android ListView SimpleAdapter ArrayList 数据更新问题 zhuan

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()就可以

你可能感兴趣的:(android)