android-fragmentactivity

Fragment as a singleton in Android

放肆的年华 提交于 2019-12-29 03:21:28
问题 General Question Can I define Fragments as Singletons? Specific question In my application I have one 'FragmentActivity' with a FragmentPager which has two Fragments, FragmentA and FragmentB . I defined the fragments as Singletons in the FragmentA extends Fragment class: private static instance = null; public static FragmentA getInstance() { if (instance == null) { instance = new FragmentA(); } return instance; } private FragmentA() {} and in my FragmentPagerAdapter : @Override public

FragmentActivity onSaveInstanceState not getting called

邮差的信 提交于 2019-12-28 05:21:30
问题 I have seen a few similar questions about onSaveInstanceState not getting called for Fragment s, but in my case Fragment s work fine, it's the main FragmentActivity that's having trouble. The relevant code looks fairly simple: public class MyFActivity extends FragmentActivity implements ActionBar.TabListener { String[] allValues; // data to save @Override protected void onSaveInstanceState (Bundle outState) { Log.d("putting it!", allValues.toString()); outState.putStringArray("allValues",

change Fragment View

江枫思渺然 提交于 2019-12-25 09:48:26
问题 I have an app with fragments. It works fine. One of the fragments has a button, and when pressed I want to change the view. public class BikeRecap extends Fragment { public static Activity activity; public static Context context; /** Called when the activity is first created. */ public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { activity = getActivity(); context = activity.getApplicationContext(); View view = inflater.inflate(R.layout.bike_recap

android combination of fragmentactivity and listactivity

空扰寡人 提交于 2019-12-25 05:21:56
问题 sorry for may be stupid question, I am a beginner. what can I do if I needed to extend both ListActivity and FragmentActivity in one activity? I know that I can extend only 1 class, but is there any trick which resolves this? Thank in advance. 回答1: you don't have to extended list activity in order to use list , you can include list View inside your layout file 回答2: No, you cannot extend 2 classes in Java. Could you specify why you need to extend both? My guess is FragmentActivity should

Removing a Fragment from a Fragment

别等时光非礼了梦想. 提交于 2019-12-25 04:04:46
问题 I have an Activity that creates a Fragment and then this Fragment creates another Fragment : Activity -> Fragment1 -> Fragment2 I am now in Fragment2 and I'd like to go back to Fragment1 by clicking on a button. In my OnClickListener of my button I have: getActivity().getSupportFragmentManager().beginTransaction().remove(fragment2.this).commit(); This brings me to the Activity . Is there actually a way to just remove Fragment2 and go to Fragment1 ? Thank you in advance for your time, I could

Android Fragment - getActivity().runOnUiThread returns null when restarting app

╄→гoц情女王★ 提交于 2019-12-25 03:57:10
问题 when I start the app the first time the code below works just fine. But when leaving the app and opening it again I get an error saying getActivity() returns null. I'm doing this code in a Fragment: (getActivity()).runOnUiThread(new Runnable() { @Override public void run() { enableMenu(); openMenu(); navigateToFragment(new BlankFragment()); } }); What to do ? How can I get the Activity ? 回答1: Create object of Activity and assign that on the onAttach Method like below. Some times getActivity

Fragment and ListFragment incompatibility

人走茶凉 提交于 2019-12-25 01:49:36
问题 I have this method that launches a page when I select it from a menu. The problem is that some of these extend Fragment like from case 1 to 6, while others extend ListFragment as in case 7. I get a: Type mismatch: cannot convert from ItemListFragment to Fragment error. How do I solve this? package com.prjma.lovertech.activity; import java.util.ArrayList; import android.app.Activity; import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Bundle;

how to return to previous fragment activity

笑着哭i 提交于 2019-12-25 00:17:29
问题 Three fragment activities: MainFragmentActivity , Reports and ReportsType . Reports is calling ReportsType . There is a back button in ReportsType to go back with the following code: public void goBackReport(View v) { finish(); // why MainFragmentActivity.java is called after finish()? } But its always returning to MainFragmentActivity.java . But it should be Reports.java . UPDATE: Reports.java public void showReport(View v) { String tag = v.getTag().toString(); Intent i5 = new Intent(this,

offscreen viewpager fragments won't render after 1st time loaded

时光总嘲笑我的痴心妄想 提交于 2019-12-24 23:46:04
问题 I have a viewpager with 5 tabs and if I go to the 5th fragment(that is the fragment loaded when I click the 5th tab or swipe to the 5th tab) and then I go to the 3rd tab the 5th fragment won't load the view anymore and if I go to the 2nd or 1st tab the 4th and 5th tabs won't. I tried changing the viewpager.offscreenlimit(3) or even 5 with no results. If it helps anyone figure it out, it happens regardless of what fragments I put in place of the 3rd 4th and 5th positions. Also, the first

Android: how to add another fragment to the main activity

烈酒焚心 提交于 2019-12-24 12:23:05
问题 I asked a question about how to add a Fragment that contained something drawn using OpenGL ES here. Someone was kind enough to answer that for me, but unfortunately today I encountered another problem. As I mentioned in my other question, my purpose is to add other Fragments next to the one that contains OpenGL and because I am a beginner in Android development I don't seem to understand how this is done. Here's what I want: right now, my code is exactly the one from my other question. I also