How to bind a view model variable with custom class type

前端 未结 2 1204
栀梦
栀梦 2021-01-29 06:06

What works?

XML:

            name=\"viewModel\"
            type=\"com. . . . .MyViewModel\" />
...
...
...


        
2条回答
  •  情话喂你
    2021-01-29 06:47

    Change this like below in viewmodel

       private MutableLiveData> feedListLivedata =  new MutableLiveData<>();;
    
    
    
     public MyViewModel() {
        //create a list of feed here
        setFeeds(feeds);
    }
    
    
    
    public void setFeeds( List  feeds) {
            feedListLivedata .postValue(feeds);
        }
    

    //create getter and setter for feed list live data.

    And now in xml

     app:items="@{viewModel.feedListLivedata }"
    

提交回复
热议问题