public class NasActivity extends Activity {
    public static final String TAG = "nasActivity";
    private Context mContext;
    ListView list;
    SimpleAdapter adapter;
    private int Pre_Num = 0;
    private String[] info;
    private String pre_name="~$";
    private String[] name={""};
    public BroadcastReceiver XXXX = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
           ....
           updateview();
        }
    };
    private void updateview() {
        getInfo();
        adapter =new SimpleAdapter(this, getData(), R.layout.listitems,
                new String[] {"name","info"},
                new int[] {R.id.name,R.id.info});
        list.setAdapter(adapter);
    }
    private void getInfo()
    {    ......
         change the info[];      
    }
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.nasview);
        list = (ListView) findViewById(R.id.ListView01);
        Pre_Num=name.length;
        info =new String[Pre_Num];
        this.registerReceiver(XXXX, new IntentFilter(
                "intent.action.XXXX"));
        getInfo();
        adapter =new SimpleAdapter(this, getData(), R.layout.listitems,
                new String[] {"name","info"},
                new int[] {R.id.name,R.id.info});
        list.setAdapter(adapter);
    }
    private List<Map<String,Object>> getData(){
        List<Map<String, Object>> list =new ArrayList<Map<String,Object>>();
        Map<String, Object> map =new HashMap<String, Object>();
        for(int i=0;i<Pre_Num;i++)
        {
            map =new HashMap<String, Object>();
            map.put("name", name[i]+pre_name);
            map.put("info", info[i]);
            list.add(map);
        }
        return list;
    }
    @Override
    public void onDestroy() {
        // TODO Auto-generated method stub
        this.unregisterReceiver(XXXX);
        super.onDestroy();
    }
}

解决方案 »

  1.   

    请问这样可以刷新吗?还是在updateview(),用notifyDataSetChanged()
    有人说SimpleAdapter 是静态的,若要刷新用notifyDataSetChanged,必须要自己继承baseadapter自己写
      

  2.   

    还有其他方法刷新吗?在updateview(),用notifyDataSetChanged()
      

  3.   


    SimpleAdapter 是静态的?  这句话没看懂,SimpleAdapter就是继承的BaseAdapter用notifyDataSetChanged()肯定可以的,要保证其第一次绑定的数据源按你需要的改变
    你getData()方法每个返回一个新的引用是不行的
      

  4.   

    有数据变化的时候notifyDataSetChanged()就可以了.都是可以刷新的