android-architecture-components

setupWithNavController method for toolbar no longer available?

北城以北 提交于 2020-04-18 05:44:13
问题 so previously I had crash with error: You must call setGraph() before calling getGraph() then after reading the solution frem here. it is said that I have to use these lines on my gradle implementation "androidx.navigation:navigation-fragment:2.3.0-alpha02" implementation "androidx.navigation:navigation-ui:2.3.0-alpha02" and the error is dissapear. but now I no longer can find setupWithNavController method. usually I use this line toolbar.setupWithNavController(navController

can I make a livedata observer in my viewmodel? or should I always observer in fragment/activity?

混江龙づ霸主 提交于 2020-04-18 05:31:43
问题 I am new to MVVM. so I have 2 requests to the server from my fragment/activity, the result from the first request will be used as an input parameter for the second request. so first in my fragment, when a button is clicked then I make a request to check whether the user is banned or not, if not then this user can create a post. so first I check if a user is banned or not using this code in my fragment class CreateEventFragment : Fragment() { lateinit var model: CreateEventViewModel override

can I make a livedata observer in my viewmodel? or should I always observer in fragment/activity?

自作多情 提交于 2020-04-18 05:29:40
问题 I am new to MVVM. so I have 2 requests to the server from my fragment/activity, the result from the first request will be used as an input parameter for the second request. so first in my fragment, when a button is clicked then I make a request to check whether the user is banned or not, if not then this user can create a post. so first I check if a user is banned or not using this code in my fragment class CreateEventFragment : Fragment() { lateinit var model: CreateEventViewModel override

why my map livedata is not called even though I have change the value?

此生再无相见时 提交于 2020-04-18 05:27:44
问题 I am new in MVVM and Android Architecture component. so I have repository like this object RestaurantRepository { val restaurants : LiveData<ArrayList<Restaurant>> = RestaurantClient.restaurants private var count : LiveData<Int> = Transformations.map(restaurants) { Log.d("debugLog","map") it.size } fun searchRestaurants(query: String, latitude:Double, longitude: Double) { mQuery = query RestaurantClient.searchRestaurants( query = query, latitude = latitude, longitude = longitude, start = 0 )

how to remove back button in the toolbar of top level fragment if I set toolbar in each fragment using navigation component?

旧城冷巷雨未停 提交于 2020-04-17 21:59:36
问题 I have tried to read this but my problem is little bit different. I need some different toolbars, so according the documentation from here , I need to set the toolbar in each of my fragment not in my MainActivity. so I set the toolbar in each xml of my fragment. and then in each fragment I use this code to set the toolbar override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val toolbar = view.findViewById<androidx.appcompat.widget

how to remove back button in the toolbar of top level fragment if I set toolbar in each fragment using navigation component?

混江龙づ霸主 提交于 2020-04-17 21:58:48
问题 I have tried to read this but my problem is little bit different. I need some different toolbars, so according the documentation from here , I need to set the toolbar in each of my fragment not in my MainActivity. so I set the toolbar in each xml of my fragment. and then in each fragment I use this code to set the toolbar override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val toolbar = view.findViewById<androidx.appcompat.widget

how to remove back button in the toolbar of top level fragment if I set toolbar in each fragment using navigation component?

℡╲_俬逩灬. 提交于 2020-04-17 21:56:19
问题 I have tried to read this but my problem is little bit different. I need some different toolbars, so according the documentation from here , I need to set the toolbar in each of my fragment not in my MainActivity. so I set the toolbar in each xml of my fragment. and then in each fragment I use this code to set the toolbar override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) val toolbar = view.findViewById<androidx.appcompat.widget

Cannot create an instance of class com.example.architectureexample.NoteViewModel

风格不统一 提交于 2020-04-17 18:45:57
问题 every time i run my app it shows this error in the title and i have searched for the problem some said make the ViewModel constructor public and mine is public other said Either: Remove the Context context and LifecycleOwner lifecycleOwner constructor parameters from your HomeViewModel, or Create a ViewModelProvider.Factory that can build your HomeViewModel instances, and use that factory with ViewModelProviders.of() and i have made the two solutions and still get the same error MainActivity

Cannot create an instance of class com.example.architectureexample.NoteViewModel

大城市里の小女人 提交于 2020-04-17 18:45:23
问题 every time i run my app it shows this error in the title and i have searched for the problem some said make the ViewModel constructor public and mine is public other said Either: Remove the Context context and LifecycleOwner lifecycleOwner constructor parameters from your HomeViewModel, or Create a ViewModelProvider.Factory that can build your HomeViewModel instances, and use that factory with ViewModelProviders.of() and i have made the two solutions and still get the same error MainActivity

Android Studio not showing available dependency update

梦想与她 提交于 2020-04-17 18:43:53
问题 I am on Android Studio 3.6.1, in my app build.gradle I have e.g. implementation 'androidx.fragment:fragment-ktx:1.2.2' There is version 1.2.3 since March 18th, yet no update hint is shown, neither when I hover over the dependency nor in Module settings -> suggestions . What could be the reason that the update isn't shown? Can I somehow trigger Android Studio manually to search for dependency updates and check when Android Studio did so last time? 回答1: You can manually check for dependency