首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏独行猫a的沉淀积累总结

    重新构建711的Android项目(二),架构的选择与实现

    <Boolean> isShow1 = new MutableLiveData<>(); private final MutableLiveData<String> payState = new MutableLiveData<>(); private final MutableLiveData<String> opFare = new MutableLiveData<>(); private final MutableLiveData<String> discFare = new MutableLiveData<>(); //卡号 private final MutableLiveData<String> cardAsn = new MutableLiveData<>(); //账户余额 private final MutableLiveData public MutableLiveData<String> getCardAsn() { return cardAsn; } public MutableLiveData

    58810发布于 2020-08-04
  • 来自专栏Android机器圈

    Android  JetPack~ LiveData (一)   介绍与使用

    3、LiveData与MutableLiveData区别 4、LiveData的使用 5、MutableLiveData的使用 6、LiveData和MutableLiveData的可变与不可变 7、 下面代码讲解 抽象类,无法直接new 2、什么是MutableLiveData MutableLiveData的父类是LiveData 用法和LiveData类似,也是在注册观察者回调里查看更新数据 可变 (下面会贴代码) MutableLiveData则是完全是整个实体类或者数据类型变化后才通知.不会细节到某个字段 4、LiveData的使用 public class UserBean extends public class MyViewModel extends ViewModel { private MutableLiveData<String> mStr; public MutableLiveData 总结: LiveData一般使用在实体类,MutableLiveData作用在变量上,他们通常和ViewModel结合使用,上面例子过于简单,工作当中可按照业务需要进行调整。

    2.8K20编辑于 2023-02-16
  • 来自专栏程序员修炼之路

    多模块数据混乱?LiveData总线污染的三种防御架构设计

    用户信息变更时触发订单异常刷新 源码定位(LiveDataBus.java): public class LiveDataBus { private final HashMap<String, MutableLiveData <Object>> eventMap = new HashMap<>(); public MutableLiveData<Object> with(String key) { return eventMap.getOrDefault(key, new MutableLiveData<>()); } } 污染原理:全局HashMap未做模块隔离,不同模块的同名 buildKey(module, domain, event) return busMap.getOrPut(key) { SafeMutableLiveData<T>() } as MutableLiveData 版本号屏障:继承MutableLiveData重写observe方法,添加版本校验逻辑 2. 事件生命周期:给每个事件绑定发布者的Context,跟随发布模块生命周期自动清理 3.

    24810编辑于 2025-05-10
  • 来自专栏loongwind

    Jetpack之LiveData详解

    对象,它是 LiveData 的子类,然后给它添加观察者对象,代码如下: java: final MutableLiveData<String> simpleLiveData = new MutableLiveData 前面介绍 Transformations 的变换操作实际上就是返回的 MediatorLiveData ,看一下 MediatorLiveData 的使用: java: MutableLiveData <User> userLiveData1 = new MutableLiveData<>(); MutableLiveData<User> userLiveData2 = new MutableLiveData <User>() val userLiveData2 = MutableLiveData<User>() val userLiveData = MutableLiveData<User>() userLiveData1 <User> userLiveData = new MutableLiveData<>(); public void loadUser(){ //...

    2.1K20编辑于 2022-09-22
  • 来自专栏Android干货

    Android项目实战(六十一):pdf文件用图片方式预览

    android.arch.lifecycle.AndroidViewModel; import android.arch.lifecycle.LiveData; import android.arch.lifecycle.MutableLiveData filename of the PDF. */ private static final String FILENAME = "sample.pdf"; private final MutableLiveData <PageInfo> mPageInfo = new MutableLiveData<>(); private final MutableLiveData<Bitmap> mPageBitmap = new MutableLiveData<>(); private final MutableLiveData<Boolean> mPreviousEnabled = new MutableLiveData <>(); private final MutableLiveData<Boolean> mNextEnabled = new MutableLiveData<>(); private

    1.1K10发布于 2020-12-21
  • 来自专栏Android相关

    AAC---LiveData

    <UserData> liveData = new MutableLiveData<>(); liveData.observe(this, new Observer<UserData>( MutableLiveData:可变的LiveData 普通的LiveData将setValue以及postValue的作用于定义成protected,除非继承LiveData否则访问这两个函数。 而MutableLiveData只是Override这两个函数,将protected作用域扩大成了public,以至于外部可以访问。 MutableLiveData<UserData> localCache = new MutableLiveData<>(); localCache.observe(this, userData -> { // TODO: }); MutableLiveData<UserData> networkData = new MutableLiveData<>(); networkData.observe

    1.3K20发布于 2018-10-24
  • 来自专栏代码男人

    Android Jetpack系列 之LiveData

    <Integer> mCount = new MutableLiveData<>(); public void add() { mCount.setValue(mCount.getValue <Integer> mCount = new MutableLiveData<>(); public void add() { mCount.postValue(mCount.getValue <Student> studentMutableLiveData = new MutableLiveData<>(); public void setStudentMutableLiveData <Student> studentMutableLiveData = new MutableLiveData<>(); Student student = new Student(); <Integer> score = new MutableLiveData<>(); public void setScore(int score) { this.score.setValue

    1.4K20发布于 2020-05-25
  • 来自专栏韩曙亮的移动开发专栏

    【Jetpack】ViewModel + LiveData + DataBinding 综合使用 ( 核心要点说明 | 组合方式 | 代码示例 )

    import androidx.lifecycle.ViewModel class MyViewModel: ViewModel() { lateinit var number: MutableLiveData <Int> init { number = MutableLiveData() number.value = 0 } } 然后 , 在 Activity 成员 ; import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel class MyViewModel : ViewModel() { lateinit var number: MutableLiveData<Int> init { number = MutableLiveData <Int> init { number = MutableLiveData() number.value = 0 } fun plus():

    2.3K21编辑于 2023-04-30
  • 来自专栏用户4077185的专栏

    Android | LiveData 源码分析

    class JokesDetailViewModel : ViewModel() { //创建 LiveData private val _state by lazy { MutableLiveData 就有了 MutableLiveData 继承 LiveData 将发送数据的方法改为了 public public class MutableLiveData<T> extends LiveData<T > { /** * Creates a MutableLiveData initialized with the given {@code value} * * @param value initial value */ public MutableLiveData(T value) { super (value); } /** * Creates a MutableLiveData with no value assigned to it. */ public

    1.5K20编辑于 2022-09-27
  • 来自专栏Android 开发者

    [译]区域设置更改和 AndroidViewModel 反面模式

    // 别这么做 public class MyViewModel extends AndroidViewModel { public final MutableLiveData<String> statusLabel = new MutableLiveData<>(); public SampleViewModel(Application context) { // 显示资源ID public class MyViewModel extends ViewModel { public final MutableLiveData<Int> statusLabel = new MutableLiveData<>(); public SampleViewModel(Application context) { super(context

    1.5K60发布于 2019-08-29
  • 来自专栏韩曙亮的移动开发专栏

    【Jetpack】LiveData 架构组件 ( LiveData 简介 | LiveData 使用方法 | ViewModel + LiveData 示例 )

    <T> , class MyViewModel: ViewModel { var second: MutableLiveData<Int> = MutableLiveData<Int>() import androidx.lifecycle.ViewModel class MyViewModel: ViewModel { var second: MutableLiveData< Int> = MutableLiveData<Int>() constructor() { second.value = 0 } } 2、Activity 组件代码 在 import androidx.lifecycle.ViewModel class MyViewModel: ViewModel { var progress: MutableLiveData <Int> = MutableLiveData<Int>() constructor() { progress.value = 0 } } 2、Activity 组件代码

    2K20编辑于 2023-03-30
  • 来自专栏Android 开发者

    [译]区域设置更改和 AndroidViewModel 反面模式

    // 别这么做 public class MyViewModel extends AndroidViewModel { public final MutableLiveData<String> statusLabel = new MutableLiveData<>(); public SampleViewModel(Application context) { // 显示资源ID public class MyViewModel extends ViewModel { public final MutableLiveData<Int> statusLabel = new MutableLiveData<>(); public SampleViewModel(Application context) { super(context

    50510编辑于 2024-01-28
  • 来自专栏android技术

    JetPack--DataBinding

    ; /** * Created by aruba on 2021/9/11. */ public class Idol { private MutableLiveData<String> name; private MutableLiveData<Integer> star; private MutableLiveData<String> imageUrl; private MutableLiveData<Integer> score; public Idol(String name, int star, String imageUrl,int score) { MutableLiveData<>(); this.star.setValue(star); this.imageUrl = new MutableLiveData<> MutableLiveData<Integer> getStar() { return star; } public MutableLiveData<String>

    1.9K10编辑于 2021-12-06
  • 来自专栏程序员开发工具

    Android LiveData 使用详解

    在实际使用中,用得比较多的是 MutableLiveData。他常常结合 ViewModel 一起使用。下面,让我们一起来看一下怎样使用它? public class TestViewModel extends ViewModel { private MutableLiveData<String> mNameEvent = new MutableLiveData<>(); public MutableLiveData<String> getNameEvent() { return mNameEvent; mTestViewModel = ViewModelProviders.of(this).get(TestViewModel.class); MutableLiveData<String> nameEvent <String> mNameEvent = new MutableLiveData<>(); public MutableLiveData<String> getNameEvent() {

    5.1K40发布于 2019-02-26
  • 来自专栏向治洪

    Android Jetpack架构组件(四)之LiveData

    public class NameViewModel extends ViewModel { private MutableLiveData<String> name; public MutableLiveData<String> getName() { if (name == null) { name = new MutableLiveData 事实上,最简单的LiveData使用方法是MutableLiveData,如下所示。 <String> mutableLiveData = new MutableLiveData<>(); mutableLiveData.observe(this, new Observer 通常情况下会在 ViewModel 中使用 MutableLiveData,然后 ViewModel 只会向观察者公开不可变的 LiveData 对象,如下所示。

    4.2K00发布于 2020-12-21
  • 来自专栏Android技术专栏

    LiveData的用法

    三.LiveData的基本使用方法   LiveData是一个抽象类,不能直接使用,通常使用的是他的直接子类MutableLiveData。 下面我们改造上一节的代码,如下所示: public class TimerViewModel extends ViewModel { private MutableLiveData<Integer LiveData<Integer> getCurrentSecond(){ if(currentSecond==null){ currentSecond=new MutableLiveData TimerViewModel timerViewModel=new ViewModelProvider(this).get(TimerViewModel.class); MutableLiveData <Integer> liveData= (MutableLiveData<Integer>) timerViewModel.getCurrentSecond(); liveData.observe

    93320编辑于 2023-10-22
  • 来自专栏深入浅出区块链技术

    开发以太坊安卓钱包系列3 - 资产信息展示

    可以订阅数据,TokensViewModel类像下面,代码[3]有删减: public class TokensViewModel extends ViewModel { private final MutableLiveData <ETHWallet> defaultWallet; private final MutableLiveData<NetworkInfo> defaultNetwork; private final MutableLiveData<Token[]> tokens; private final MutableLiveData<Ticker> prices; } MutableLiveData 显示当前账号 可以分为两个步骤: •从数据库中读取账号;•界面显示账号 TokensViewModel中定义了一个MutableLiveData<ETHWallet> defaultWallet ,从数据库中读取账号会保存在

    1.5K30发布于 2019-04-28
  • 来自专栏刘晓杰

    Jetpack:LiveData

    2.用法 (1)创建LiveData对象 public class UserModel extends ViewModel { private MutableLiveData<String> name ; int age; public MutableLiveData<String> getName() { if (name == null) { name = new MutableLiveData<>(); name.setValue("lalalala"); } return name;

    81420发布于 2020-06-03
  • 来自专栏嵌入式音视频

    安卓UI

    <String> msg; private MutableLiveData<Integer> count; private MutableLiveData<List<ImageInfo >> data; public MutableLiveData<Integer> getCount() { if (count == null) { count = new MutableLiveData<>(); } return count; } public MutableLiveData<String> msg; } public MutableLiveData<List<ImageInfo>> getData() { if(data == null){ data = new MutableLiveData<>(); } return data; } } 4.MainActivity.java public class

    5K30编辑于 2022-12-01
  • 来自专栏vivo互联网技术

    Jetpack—LiveData组件的缺陷以及应对策略

    我们首先定义一个极简的ViewModel: public class TestViewModel extends ViewModel { private MutableLiveData<String > currentName; public MutableLiveData<String> getCurrentName() { if (currentName == null) { currentName = new MutableLiveData<String>(); } return currentName; 看下Kotlin中 lambda的写法: fun test2() { val liveData = MutableLiveData<Int>() for (i in 0..9) liveData = new MutableLiveData(); int i = 0; do { int i2 = i; i+

    1.5K20编辑于 2022-01-19
领券