android-fragmentactivity

Android get view of fragment in activity [duplicate]

徘徊边缘 提交于 2021-02-11 14:34:08
问题 This question already has answers here : findViewById in Fragment (35 answers) Closed 8 months ago . I have an activity, let's call it A , and it launches a fragment like so: remoteFragment = new RemoteFragment(); getSupportFragmentManager() .beginTransaction() .replace(R.id.frameLayout_remote_activity, remoteFragment) .commit(); my remoteFragment looks something like this: public Button okBtn; public RemoteFragment() { // Required empty public constructor } @Override public View onCreateView

How to handle rotate screen and save data in Fragment?

笑着哭i 提交于 2021-02-08 08:20:05
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

How to handle rotate screen and save data in Fragment?

拈花ヽ惹草 提交于 2021-02-08 08:17:24
问题 I have 3 Fragment (Fragment Home, Fragment A, Fragment B and Fragment C). First time app run will display Fragment Home (Set in Mainactivity). From Navigation Draw Item can choose every fragment. Every selected item will display detail Fragment. I have problems to handle data and retain fragment : (1). When I select a fragment (for example Fragment A) will show the page of Fragment A. But when I rotate the device, why my fragment back to Fragment Home and not stay at current Fragment ??How to

Android Set Text of TextView in Fragment that is in FragmentPagerAdapter

房东的猫 提交于 2021-02-06 04:21:16
问题 This one is driving me nuts. Basically, I want to create a ViewPager and add a few Fragment s to it. Then, all I want to do, it set a value in one of the Fragment 's TextView s. I can add the Fragment s fine, and they attach, but when I go to findViewById() for one of the TextView s in the first Fragment it throws a NullPointerException . I, for the life of me, can't figure out why. Here's my code so far, let me know if more is needed please. public class SheetActivity extends

Why is it necessary to implement OnFragmentInteractionListener when setting up a fragment?

守給你的承諾、 提交于 2021-01-29 13:55:05
问题 I followed the official documentation: https://developer.android.com/guide/components/fragments#Creating. It provides the steps to set up a fragment. First, create the fragment class (`extends Fragment') Then create its layout (and, in fragment class' OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) , return one of the View' of this layout using inflate`) Choose an activity that will use this fragment. This activity must extends FragmentActivity and in

can't use method “getString(int resId)” in FragmentPagerAdapter

99封情书 提交于 2020-08-22 19:15:56
问题 I've the following class in my fragment activity now i want to get name of tabs from strings.xml but i can't able to use method getString(int resId) it gives a error message "Cannot make a static reference to the non-static method getString(int) from the type Context". In method public CharSequence getPageTitle(int position) I need to get like this name = getString(R.string.mystring) any help is appreciated. public static class AppSectionsPagerAdapter extends FragmentPagerAdapter { public