android-jetpack

Android jetpack navigation component result from dialog

不打扰是莪最后的温柔 提交于 2020-07-05 07:39:33
问题 So far I'm successfully able to navigate to dialogs and back using only navigation component. The problem is that, I have to do some stuff in dialog and return result to the fragment where dialog was called from. One way is to use shared viewmodel. But for that I have to use .of(activity) which leaves my app with a singleton taking up memory, even when I no longer need it. Another way is to override show(fragmentManager, id) method, get access to fragment manager and from it, access to

Android jetpack navigation component result from dialog

时光总嘲笑我的痴心妄想 提交于 2020-07-05 07:39:32
问题 So far I'm successfully able to navigate to dialogs and back using only navigation component. The problem is that, I have to do some stuff in dialog and return result to the fragment where dialog was called from. One way is to use shared viewmodel. But for that I have to use .of(activity) which leaves my app with a singleton taking up memory, even when I no longer need it. Another way is to override show(fragmentManager, id) method, get access to fragment manager and from it, access to

Setting NavGraph programmatically

时光毁灭记忆、已成空白 提交于 2020-06-25 10:00:43
问题 In my activity layout, I have the following NavHostFragment : <fragment android:id="@+id/my_nav_host_fragment" android:layout_height="match_parent" android:layout_width="match_parent" android:name="androidx.navigation.fragment.NavHostFragment" app:defaultNavHost="true" app:navGraph="@navigation/my_nav_graph" /> My question is how can I set the navGraph programmatically? How can I convert the my_nav_host_fragment view instance in a NavHostFragment instance? 回答1: I found a solution: //Setup the

Updating a single item in a recylerview. I am using paging library and would like to update a single item/row

馋奶兔 提交于 2020-06-25 06:49:30
问题 I am passing pagedlist values to adapter using submit list. when i update a single item consider i am clicking a like button of a feed in a recyclerview. how to update the single item. i am following this example for paging implementation https://github.com/saquib3705/PagingLibrarySampleApp which just loads data and update the recyclerview. I would like to add like button for the items and update the list when user liked how to achieve it. Also look at this which is what i m exactly looking

Initializing ViewModel in fragment Android java

回眸只為那壹抹淺笑 提交于 2020-06-17 09:17:16
问题 I am trying to initialize my viewmodel object in the FirstFragment.java file of BasicActivity . All theses four codes are failed. The documentation could not help me much. mViewModel = new ViewModelProvider(this).get(MyViewModel.class); mViewModel = new ViewModelProvider(requireActivity()).get(MyViewModel.class); mViewModel = new ViewModelProvider(getActivity()).get(MyViewModel.class); mViewModel = new ViewModelProvider(FirstFragment.class).get(MyViewModel.class); On the other hand, public

ConstraintLayout hides the last line of TextView with app:layout_constrainedHeight=“true”

旧巷老猫 提交于 2020-05-27 13:13:26
问题 The bounty expires in 1 hour . Answers to this question are eligible for a +50 reputation bounty. Nominalista wants to draw more attention to this question. I have noticed weird behavior of ConstraintLayout (version 1.1.3) that hides the last line of TextView whenever I try to use height with wrap_content property and layout_constrainedHeight is set to true . With layout_constrainedHeight : With no layout_constrainedHeight : Source code: <?xml version="1.0" encoding="utf-8"?> <androidx

Android Navigation Component with Transition from Drawerlayout

痴心易碎 提交于 2020-05-27 06:17:51
问题 Is it possible to change the transition effect from opening a fragment from a drawerlayout with the android navigation component. There is nothing in the android docs. 回答1: Sarah! Yes, it is possible. You can add your custom listener to handle navigation item selection and add animation there. I had to add one myself, for other purposes, but it definitely fits as a solution for your task. How to: Add layout with drawer. Example: <?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout

Android Navigation Component with Transition from Drawerlayout

杀马特。学长 韩版系。学妹 提交于 2020-05-27 06:17:05
问题 Is it possible to change the transition effect from opening a fragment from a drawerlayout with the android navigation component. There is nothing in the android docs. 回答1: Sarah! Yes, it is possible. You can add your custom listener to handle navigation item selection and add animation there. I had to add one myself, for other purposes, but it definitely fits as a solution for your task. How to: Add layout with drawer. Example: <?xml version="1.0" encoding="utf-8"?> <androidx.drawerlayout

navigate to a fragment from another graph without it being the start destination

蹲街弑〆低调 提交于 2020-05-23 10:48:21
问题 In my first graph, I have the following: <?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/firstGraph" app:startDestination="@id/listFragment"> <fragment android:id="@+id/listFragment" android:name="com.example.ListFragment"> <action android:id="@+id/action_list_to_details" app:destination="@id/detailsFragment" /> <

How to update a single item in a PagedListAdapter

时间秒杀一切 提交于 2020-05-15 10:11:06
问题 I've implemented the new PagedListAdapter with an ItemKeyedDataSource. My list contains feed items with a like button. A click on the like button should refresh the item. To refresh my list item on a like button click, i update the state in my Firestore back-end, and call invalidate on my ItemKeyedDataSource. But this will refresh my whole list while jumping back to the top of my list. I wasn't sure if this is normal behaviour, so i went debugging and checking maiby my DiffUtil.ItemCallback