第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

雙向數(shù)據(jù)綁定:從內(nèi)部類更新值時(shí)無法更改 EditText 值

雙向數(shù)據(jù)綁定:從內(nèi)部類更新值時(shí)無法更改 EditText 值

皈依舞 2022-10-20 17:29:53
我試圖通過profile.setClientName("Name");從Observer<T>'onChanged事件調(diào)用來更新我的 EditText 中的值,但 EditText 不反映更改。onCreateView如果從我的片段中調(diào)用上述代碼行,則 EditText 會(huì)更新。這是我的代碼:ClientProfileFragment.javapublic class ClientProfileFragment extends Fragment implements View.OnClickListener {    private ClientProfile profile; //The BaseObservable     private CPViewModel mViewModel;    @Override    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,                         @Nullable Bundle savedInstanceState) {        ...        ClientProfileFragmentBinding binding = DataBindingUtil.inflate(inflater,            R.layout.client_profile_fragment, container, false);        clientProfileView = binding.getRoot();        profile = new ClientProfile();        binding.setClientprofile(profile);        final Observer<ClientProfile> clientProfileObserver = new Observer<ClientProfile>() {            @Override            public void onChanged(ClientProfile clientProfile) {            profile.setClientName("Name"); //This line gets executed. Confirmed.            }        };        mViewModel.getClientProfile().observe(this, clientProfileObserver);        //If I call profile.setClientName("Name"); from here then the corresponding        //EditText changes to "Name".        return clientProfileView;    }    @Override    public void onClick(View v) {        customerFindFuture.then(new FutureCallback<Response<String>>() {            @Override            public void onCompleted(Exception e, Response<String> result) {                Gson gson = new GsonBuilder().serializeNulls().create();                ClientProfileWrapper clientProfileWrapper =                            gson.fromJson(result.getResult(), ClientProfileWrapper.class);                profile = clientProfileWrapper.getData().get(0);                mViewModel.getClientProfile().setValue(profile);                }            }        }    }}
查看完整描述

1 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

事實(shí)證明,我必須在為 egbinding.setClientprofile(profile);賦值后調(diào)用profile


profile = clientProfileWrapper.getData().get(0);

binding.setClientprofile(profile);

notifyPropertyChanged(BR._all);

這樣做會(huì)使用當(dāng)前所需的值填充 EditText 字段。


查看完整回答
反對(duì) 回復(fù) 2022-10-20
  • 1 回答
  • 0 關(guān)注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)