当前位置: 代码迷 >> Android >> listview SimpleAdapter 刷新有关问题
  详细解决方案

listview SimpleAdapter 刷新有关问题

热度:42   发布时间:2016-05-01 12:19:51.0
listview SimpleAdapter 刷新问题

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++)
        {
  相关解决方案