Android Adapter,UI界面更新

来源:互联网 发布:手机淘宝客软件 编辑:程序博客网 时间:2024/05/02 21:50

Android Adapter,UI界面更新方法:
(广播处理器,普通方法onstart()和onresume(),handler中更新UI)

1:广播处理器
MusicPlayerActivity:

ArrayList<Music> musics = new MusicBiz(MusicPlayerActivity.this).getLocalMusics();    app.setMusics(musics);// 更新共享的播放列表数据,更新数据.    adapter.changeDataSet(musics);// 更新界面

MusicAdapter:

public void setMusics(ArrayList<Music> musics) {        if (musics != null)            this.musics = musics;        else            this.musics = new ArrayList<Music>();    }    public void changeDataSet(ArrayList<Music> musics) {        this.setMusics(musics);        this.notifyDataSetChanged();    }

2:普通方法onstart()和onresume()
StuMainActivity:

protected void onResume() {        String order = pref.getString("pref_key_sort_col", "_id");        adapter.changeDataSet(biz.getStudents(order));    }

StudentAdapter:

public void setStudents(ArrayList<Student> students) {        if (students != null)            this.students = students;        else            this.students = new ArrayList<Student>();    }public void changeDataSet(ArrayList<Student> students) {        this.setStudents(students);        this.notifyDataSetChanged();    }

3:handler中更新UI
FSPointActivity handler中:

ckb = (CustomKeywordsBean) msg.obj;    keywords = ckb.getKeywords();    adapter.dateChanged(keywords);

PointsAdapter:

public void setKeywords(ArrayList<CustomKeyword> keywords) {        if (keywords != null) {            this.keywords = keywords;        } else {            this.keywords = new ArrayList<CustomKeyword>();        }    }public void dateChanged(ArrayList<CustomKeyword> keywords) {        this.setKeywords(keywords);        this.notifyDataSetChanged();    }
0 0
原创粉丝点击