Android Adapter,UI界面更新

这篇博客探讨了在Android应用中更新UI界面的三种方法:1)使用广播处理器在MusicPlayerActivity和MusicAdapter中操作;2)通过onStart()和onResume()生命周期方法在StuMainActivity和StudentAdapter中更新;3)利用Handler在FSPointActivity和PointsAdapter中实现UI刷新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值