mvvm

Reacting to activity lifecycle in ViewModel

白昼怎懂夜的黑 提交于 2021-02-18 04:38:08
问题 I'm trying to create an app which will use MVVM architecture and there's one thing I quite don't understand. Official Android docs say that's not a good idea to reference activity context in ViewModel's (as ViewModel may outlive activity) so I've started to wonder about usecase when I want to execute some action when my activity is resumed. I know ViewModel's shouldn't do business logic themselves but even if I use some service class (let's say GPSService which has to start and pauseeach time

EventSetter in DataGridComboBoxColumn throws NullReferenceException

佐手、 提交于 2021-02-16 23:35:11
问题 I'm trying to bind the SelectionChanged to a command in the code below. <EventSetter Event="SelectionChanged" Handler="{Binding MyCommand}" /> But unfortunately I'm gettin an NullReferenceException at InitializeComponent(); What can be the problem? The program works if I remove the above single line. <StackPanel> <DataGrid ItemsSource="{Binding Items}" AutoGenerateColumns="False"> <DataGrid.Columns> <DataGridTextColumn Header="Name" Binding="{Binding Name}"/> <DataGridComboBoxColumn Header=

Bind to property only if it exists

不打扰是莪最后的温柔 提交于 2021-02-16 16:28:05
问题 I have a WPF window that uses multiple viewmodel objects as its DataContext. The window has a control that binds to a property that exists only in some of the viewmodel objects. How can I bind to the property if it exists (and only if it exists). I am aware of the following question/answer: MVVM - hiding a control when bound property is not present. This works, but gives me a warning. Can it be done without the warning? Thanks! Some example code: Xaml: <Window x:Class="WpfApplication1

vue核心原理实现

放肆的年华 提交于 2021-02-13 03:50:02
<! DOCTYPE html > < html > < head > < meta charset ="utf-8" > < title > vue 核心源码 </ title > </ head > < body > < div id ="app" > </ div > </ body > < script > /* 观察者 包含可观察对象 订阅与发布方法 */ var tempSubscript = '' ; // 存储可观察者对象,方便加入到观察者队列中 function Observer(){ this .$queue = []; } /* 可观察者对象加入到观察者队列中 */ Observer.prototype.subscirpt = function (){ this .$queue.push(tempSubscript); }; /* 通知队列中的可观察者对象更新结点内容 */ Observer.prototype.notify = function (){ for (let i = 0 ;i < this .$queue.length;i ++ ){ this .$queue[i].update(); } } /* 可观测者对象 包含更新方法 */ function Observerable(propName,node,data){ this .

Kotin lateinit Var Not initialized - Android Studio

跟風遠走 提交于 2021-02-11 14:02:31
问题 I am working on a simple contact app that stores the contact's name, email, and number. Language: Kotlin Architecture: MVVM But I am getting an error: lateinit property addContactViewModel has not been initialized Activity: class AddContact : AppCompatActivity() { private lateinit var addContactViewModel : AddContactViewModel companion object{ const val EXTRA_REPLY = "com.room.contacts.REPLY" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val binding

Parcelable Model reinstatiates, MVVM Room LiveData

落花浮王杯 提交于 2021-02-11 14:01:17
问题 Here is my problem, I am using mvvm to load profile data from Dao, which was earlier updated when user logs in. Or if a new user an empty model loads. see my BasicProfileFragment and ViewModel. I am using LiveData to update fragment from Dao initially. Next, I want to edit/update the fields in different ways. keyboard input and updating data by Navigating to other fragments. Where data loaded as list from server. For eg. clicking the Gender strip and Navigate to Gender Fragment, Data

面试MySQL,看这篇文章就够了!

爱⌒轻易说出口 提交于 2021-02-11 13:38:11
当游戏前端开发能力不断提升后,有的小伙伴已经开始不满足了,将魔爪伸向后端开发,立志做一个全栈游戏开发程序员!分享一篇MySQL的好文,加油吧!程序员! 作者:zhangqh segmentfault.com/a/1190000012155267 一、EXPLAIN 做MySQL优化,我们要善用 EXPLAIN 查看SQL执行计划。 下面来个简单的示例,标注(1,2,3,4,5)我们要重点关注的数据 type列,连接类型。一个好的sql语句至少要达到range级别。杜绝出现all级别 key列,使用到的索引名。如果没有选择索引,值是NULL。可以采取强制索引方式 key_len列,索引长度 rows列,扫描行数。该值是个预估值 extra列,详细说明。注意常见的不太友好的值有:Using filesort, Using temporary 二、SQL语句中IN包含的值不应过多 MySQL对于IN做了相应的优化,即将IN中的常量全部存储在一个数组里面,而且这个数组是排好序的。但是如果数值较多,产生的消耗也是比较大的。再例如: select id from table_name where num in(1,2,3) 对于连续的数值,能用 between 就不要用 in 了;再或者使用连接来替换。 三、SELECT语句务必指明字段名称 SELECT *增加很多不必要的消耗(cpu、io

How to load a Picker in Xamarin forms with data received from the Web Api?

≯℡__Kan透↙ 提交于 2021-02-11 12:46:08
问题 So, this is my Model Class "Usuario" This class has the Foreign key "IdTipoUsuario" that was declared in my database from SQL Server Management Studio. So I placed it here with the "IList" property: namespace APPiGarbage.Models { public class Usuario { public int IdUsuario { get; set; } public string Nome { get; set; } public string Foto { get; set; } public string Descricao { get; set; } public string Email { get; set; } public string Senha { get; set; } public IList<TipoUsuario>

How to load a Picker in Xamarin forms with data received from the Web Api?

百般思念 提交于 2021-02-11 12:45:24
问题 So, this is my Model Class "Usuario" This class has the Foreign key "IdTipoUsuario" that was declared in my database from SQL Server Management Studio. So I placed it here with the "IList" property: namespace APPiGarbage.Models { public class Usuario { public int IdUsuario { get; set; } public string Nome { get; set; } public string Foto { get; set; } public string Descricao { get; set; } public string Email { get; set; } public string Senha { get; set; } public IList<TipoUsuario>

Observing MediatorLiveData Issue

穿精又带淫゛_ 提交于 2021-02-11 12:32:23
问题 I have the following LiveData variables in my ViewModel (simplified example): val currentUser : LiveData<UserObject> val allSites : LiveData<ArrayList<SiteObject>> val filterSitesForUser : LiveData<Boolean> val orderSitesByField : LiveData<String> val orderSitesDirection : LiveData<Query.Direction> val searchFilterSitesText : LiveData<String> I'm trying to use MediatorLiveData to have one 'stream' of data connecting to my RecyclerView . I therefore also have the following code in the