android-fragments

How to pass data between fragments when using bottomNavView

三世轮回 提交于 2020-06-26 14:14:29
问题 I have an app with one activity and two fragments, And I navigate using jetpack navigation. In my "Main" fragment, I've a button that trigger function inside the viewModel: edit_text_button.setOnClickListener { homeViewModel.onButtonClicked() } onButtonClicked inside viewModel , basically shuffle the list and trigger observer in main fragment. fun onButtonClicked() { initList = (1..9).shuffled() _list.value = initList } My question is: How can I pass every time the updated list to the second

Adding a fragment, a “wrong second argument type” error occurs

≡放荡痞女 提交于 2020-06-26 12:22:22
问题 I have checked similar posts and their solutions do not seem to work. I am (obviously) new to this, so it may just be a lack of skill on my part. I am receiving the error: "Wrong 2nd argument type Found:'mycompany.fragment_test... required: 'android.support.v4.app.Fragment replace (int, android.support.v4.ap.Fragment) to (int, mycompany.fragment_test...)' import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v4.app

Adding a fragment, a “wrong second argument type” error occurs

旧城冷巷雨未停 提交于 2020-06-26 12:19:00
问题 I have checked similar posts and their solutions do not seem to work. I am (obviously) new to this, so it may just be a lack of skill on my part. I am receiving the error: "Wrong 2nd argument type Found:'mycompany.fragment_test... required: 'android.support.v4.app.Fragment replace (int, android.support.v4.ap.Fragment) to (int, mycompany.fragment_test...)' import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v4.app

How can you update Day Night Mode Instantly in PreferenceFragment?

六月ゝ 毕业季﹏ 提交于 2020-06-26 06:34:33
问题 I've seen some apps like Pocket that can toggle between Day and Night mode in the settings instantly without reloading, but I'm not able to do that in my own example: public class SettingsActivity extends PreferenceActivity { @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFragmentManager().beginTransaction().replace(android.R.id.content, new PrefsFragment()).commit(); } public static class PrefsFragment extends PreferenceFragment{

Android Viewpager fragments refreshed when swiped

孤者浪人 提交于 2020-06-26 04:14:31
问题 I am new in Android and I don't really understand why a Fragment 's content which was added dynamically (for example some image which was added after a button click) is disappearing after scrolling some count of Fragment s and then come back. There is really simple code Activity and Fragment : public class MyActivity extends FragmentActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final ViewPager

Closed fragment still appearing under base fragment

£可爱£侵袭症+ 提交于 2020-06-17 11:36:10
问题 I have 5 fragments (home, settings, newPost, notifications and profile) inside my Main2Activity. Inside HomeFragment I have a RecyclerView with a lot of post views, every post containing an "open" button which should open a PostFragment . After the PostFragment is opened I have 3 options to go back to HomeFragment : by tapping phone's 'back' button, tapping my post's XML "back" button or tapping Home from the bottomNavView . The problem is that after PostFragment disappears and my screen goes

Closed fragment still appearing under base fragment

北战南征 提交于 2020-06-17 11:35:03
问题 I have 5 fragments (home, settings, newPost, notifications and profile) inside my Main2Activity. Inside HomeFragment I have a RecyclerView with a lot of post views, every post containing an "open" button which should open a PostFragment . After the PostFragment is opened I have 3 options to go back to HomeFragment : by tapping phone's 'back' button, tapping my post's XML "back" button or tapping Home from the bottomNavView . The problem is that after PostFragment disappears and my screen goes

getArguements() in Fragment not reading the strings sent from Activity

☆樱花仙子☆ 提交于 2020-06-17 10:01:08
问题 I am creating a chat app. So trying to send logged in username and one of the the user from userlist to a Fragment which receives these Strings and accordingly saves data as user_chatbuddy child in firebase. The data put in bundle does show same values on Toast when is use "bundle.toString()" on Toast. However the getArguements() in the sendMsgFragment is getting only null values. Here are the relevant codes - UsersList.java code - usersList.setOnItemClickListener(new AdapterView

getArguements() in Fragment not reading the strings sent from Activity

流过昼夜 提交于 2020-06-17 10:00:11
问题 I am creating a chat app. So trying to send logged in username and one of the the user from userlist to a Fragment which receives these Strings and accordingly saves data as user_chatbuddy child in firebase. The data put in bundle does show same values on Toast when is use "bundle.toString()" on Toast. However the getArguements() in the sendMsgFragment is getting only null values. Here are the relevant codes - UsersList.java code - usersList.setOnItemClickListener(new AdapterView

Problem in Saving State of Webview inside Fragment

早过忘川 提交于 2020-06-17 09:18:26
问题 I have 3 fragments in my App.1 fragment is having webview. I am using recyclerview.Using onclick method to switch between fragments. FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.replace(R.id.fragment, fragment); fragmentTransaction.commit(); I tried below code to save state of fragment public void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); webView.saveState(outState); } public void