android-fragments

How to set menu items in a fragment toolbar?

巧了我就是萌 提交于 2020-04-14 03:46:45
问题 I have a fragment in my Activity and the fragment has its own toolbar. Like this: Image Here is the layout of the fragment: <FrameLayout 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:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.hometsolutions.space.Fragments.ControlFragment"> <LinearLayout android:layout_width="match_parent" android

AndroidTests stopped building after adding androidx.fragment:fragment-testing dependency

邮差的信 提交于 2020-04-13 07:02:28
问题 After I have added fragment-testing dependency to my project: // Testing dependencies espressoVersion = '3.2.0-beta01' testCoreVersion = '1.1.0' runnerVersion = '1.1.0' extJunitVersion = '1.1.0' testRulesVersion = '1.1.0' fragmentVersion = '1.1.0-alpha09' orchestratorVersion = '1.1.0' uiAutomatorVersion = '2.2.0' junitVersion = '4.12' mockitoVersion = '2.7.22' robolectricVersion = '4.2.1' liveDataTestingVersion = '1.1.0' androidArchCoreTestingVersion = '2.0.0' androidTestImplementation(

BottomNavigationView setSelectedItemId crash

微笑、不失礼 提交于 2020-04-11 12:24:10
问题 I'm writing an app using BottomNavigationView and Fragment for updating the layout programmatically. I'm trying to use a Stack to allow the user to click back and return to the previous fragment. I had tried to use addToBackStack after inflating a new fragment but when back is pressed despite the layout is changing correctly the selected item menu does not change with it. So I decided to create a custom stack of Fragment and change with setSelectedItemId the selected item but this operation

How to display a date like Whatsapp on scrolling ListView

*爱你&永不变心* 提交于 2020-04-11 11:36:10
问题 How can I show dates in an app when I scroll the ListView like in WhatsApp? See the below image for clarity: When I scroll the ListView, the date gets displayed over the list. If you still did not understand my question please open your WhatsApp, go to any group & start scrolling: you will see the date getting displayed for older texts. 回答1: To show date like this screenshot, you can use val firstVisiblePosition = layoutManager.findFirstVisibleItemPosition() if (getDateFromFirebaseTime

getSupportFragmentManager().findFragmentById returns null for google maps in fragment in android?

ぐ巨炮叔叔 提交于 2020-04-10 07:30:35
问题 I have a problem with Google Maps, i.e. getSupportFragmentManager().findFragmentById returns always null. Do you have an idea how to solve this? Here is the code: fragment_map.xml: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.myapp.something.MapFragment"> <fragment android:id="@+id/map" android:layout_width="match_parent" android

Android InstantiationException With Fragment (It Is Public)

China☆狼群 提交于 2020-04-10 07:12:31
问题 I have a Fragment (it is not an inner class, and it does not have any constructor whatsoever) public class PreferenceListFragment extends ListFragment implements OnClickListener I'm getting this crash report on the Android Developer Console: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.redacted.redacted/com.redacted.redacted.PreferenceActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.redacted.redacted

Android InstantiationException With Fragment (It Is Public)

北城余情 提交于 2020-04-10 07:12:28
问题 I have a Fragment (it is not an inner class, and it does not have any constructor whatsoever) public class PreferenceListFragment extends ListFragment implements OnClickListener I'm getting this crash report on the Android Developer Console: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.redacted.redacted/com.redacted.redacted.PreferenceActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.redacted.redacted

You must call setGraph() before calling getGraph()

会有一股神秘感。 提交于 2020-04-10 04:49:48
问题 I have bottom Navigation also I'm replacing the <fragment> tag with FragmentContainerView it gives me error about does not have a NavController set on, then i was posted this question and fixed the problem, but I got this below error when orientation is changed and selecting item in Bottom Navigation java.lang.IllegalStateException: You must call setGraph() before calling getGraph() FragmentContainer <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name

Changing Toolbar and CollapsingToolbarLayout scroll flags programmatically

≯℡__Kan透↙ 提交于 2020-04-09 08:53:35
问题 I have a single Activity android app with lots of fragments. When I'm showing a list screen I want to use the Toolbar with the, app:layout_scrollFlags="scroll|enterAlways" property. And in the detail fragments I want to use the CollapsingToolbarLayout with an image in it. Since it's a single Activity app, I have only one Toolbar . Is it possible to modify my layout programmatically to suit both cases? 回答1: Yes. Let's say you are going from the CollapsingToolbarLayout fragment to the Toolbar

Changing Toolbar and CollapsingToolbarLayout scroll flags programmatically

允我心安 提交于 2020-04-09 08:49:01
问题 I have a single Activity android app with lots of fragments. When I'm showing a list screen I want to use the Toolbar with the, app:layout_scrollFlags="scroll|enterAlways" property. And in the detail fragments I want to use the CollapsingToolbarLayout with an image in it. Since it's a single Activity app, I have only one Toolbar . Is it possible to modify my layout programmatically to suit both cases? 回答1: Yes. Let's say you are going from the CollapsingToolbarLayout fragment to the Toolbar