-
使用MVVM 實(shí)現(xiàn)需求
查看全部 -
mvvm
v層跟mvp中v層是一個意思代表Activity、Fragment
v?vm?m
查看全部 -
MVVM模式需要依靠DataBinding
DataBinding 是谷歌官方發(fā)布的一個實(shí)現(xiàn)數(shù)據(jù)與視圖的雙向綁定的框架,DataBinding可以幫助我們再安卓中更好的實(shí)現(xiàn)mvvm模式
DataBinding 使用步驟
1、啟用DataBinding,讓項(xiàng)目支持DataBinding, 在項(xiàng)目buuld.grale文件,android節(jié)點(diǎn)下配置
dataBinding?{ ????enabled=?true }//啟動DataBinding
2、修改布局文件為DataBinding布局, 選中布局中根布局,如LinearLayout,快捷鍵Alt+Enter鍵選中binding layout轉(zhuǎn)換成DataBinding布局, 同時(shí)系統(tǒng)會自動生成ActivityxxBinding (默認(rèn)布局文件的大寫), 例如
ActivityDemoBinding?binding?=?DataBindingUtil.setContentView(this,?R.layout.activity_demo); binding.tvInfo.setText(""); 布局中 <data> ????<variable ????????name="account" ????????type="study.com.myapplication.bean.Account"> ????</variable> ????<variable ????name="activity" ????type="study.com.myapplication.databinding.DemoActivity"> </variable> </data> 聲明引用account android:onClick="@{activity.onclick}" android:text="@{account.name?+'|'?+?account.level}" 布局的account對象是在Activity中傳入 account?=?new?Account(); account.setName("TEST"); account.setLevel(100); binding.setAccount(account); binding.setActivity(this);
3、數(shù)據(jù)綁定, 沒有需要重新rebuild project下
數(shù)據(jù)更新
int?level?=?account.getLevel(); account.setLevel(level+1); binding.setAccount(account); 若不想每次setAccount更新?在模型類繼承BaseObservable
@Bindable public?int?getLevel()?{ ????return?level; } public?void?setLevel(int?level)?{ ????this.level?=?level; ????notifyPropertyChanged(BR.level); }
默認(rèn)更新數(shù)據(jù),要想顯示數(shù)據(jù)視圖的雙向綁定加=,例如
android:onClick="@={activity.onclick}"
android:text="@={account.name?+'|'?+?account.level}"
一般用于EditText輸入框。
查看全部 -
使用mvc實(shí)現(xiàn)需求
1、要將數(shù)據(jù)的獲取與界面的展示分離, 就是把Model和view層分離出
2、各層通信,用controller層通知Model層獲取數(shù)據(jù),通知方法是controller層持有model 層的引用, Model層請求數(shù)據(jù)結(jié)果后view層更新展示界面, 通知controller層
查看全部 -
66666666666666
查看全部 -
mvvm模式查看全部
-
MVP實(shí)現(xiàn)需求查看全部
-
肯墨跡啦咯啦咯啦咯啦查看全部
-
可就是查看全部
-
大致看一看查看全部
-
這個不錯123123
查看全部 -
111111111111查看全部
-
wwwwww查看全部
-
1111111查看全部
-
這用的什么軟件查看全部
舉報(bào)