android-fragmentactivity

Navigation drawer, handling the back button to go to previous fragments?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 11:34:24
I'm using the built in navigation drawer to run my app. I can't quite figure out how to handle the back button. When it's pressed I want it to load the very first fragment again. Fragment1. So when the app launches you see Fragment1 launched. They can then click on Fragment 2-5 to go to other pages. Within all of these pages I want the back button to take the user back to Fragment1. The only place the user should be able to exit the app via the back button is Fragment1. SInce it's all handled by a FragmentActivity I tried messing with the backbutton there. I keep getting a force close error

commitAllowingStateLoss() in fragment activities

蹲街弑〆低调 提交于 2019-11-27 11:20:18
my app uses fragment activities, it is in portrait mode only and there is no way to rotate the screen. Originally I was using the commit() method but now I plan to indiscriminately change these to commitAllowingStateLoss() for the fragment activities Is there any reason not to indiscriminately do this without re-evaluating each individual case where I use a fragment? IanB If I understand correctly you mean : Is there any reason NOT to indiscriminately do this without re-evaluating each individual case where I use a fragment? The answer is Yes - you should not do this without carefully re

How can I put titles in ViewPager using fragments?

蓝咒 提交于 2019-11-27 11:01:14
问题 I am using ViewPager to allow user to swipe between fragments. How can I add a the title of each fragment to the screen? package com.multi.andres; import java.util.List; import java.util.Vector; import com.viewpagerindicator.TitlePageIndicator; import com.viewpagerindicator.TitleProvider; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app

Fragment activity communication by passing Context object to onAttach()

我们两清 提交于 2019-11-27 08:47:55
问题 Im trying to implement fragment to activity communication. Went through android developer doc where an Activity object is passed to onAttach life cycle and set up the Fragment-Activity communication. This documentation asks to pass Context object instead of Activity. I replaced all the Activity objects by Context objects in the life cycle method onAttach. But it is throwing a NullPointerException while calling the method of the interface from Fragment. @Override public void onAttach(Context

Communication between Fragments

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:33:12
问题 I have default Master-Detail flow, which was created automatically when creating new project. My question is. When I add a button to detail side. Is there a way to update my list side by pressing that button ? In other words, can ItemDetailFragment and ItemListFragment communicate ? 回答1: Yes just communicate through the activity with a listener. Your activity: public class MyActivity extends FragmentActivity implements OnFragmentClickListener { @Override public void OnFragmentClick(int action

FragmentPagerAdapter getItem is not called

☆樱花仙子☆ 提交于 2019-11-27 06:02:40
I am not able to reuse fragment in FragmentPagerAdapter.. Using destroyItem() method, It is deleting the fragment but still does not called getItem() again..There are just 2-3 Images so I am using FragmentPagerAdapter Instead of FragmentStatePagerAdapter.. public class ExamplePagerAdapter extends FragmentPagerAdapter { ArrayList < String > urls; int size = 0; public ExamplePagerAdapter(FragmentManager fm, ArrayList < String > res) { super(fm); urls = res; size = urls.size(); } @Override public int getCount() { if (urls == null) { return 0; } else { return size; } } @Override public void

Hide/Show Action Bar Option Menu Item for different fragments

落爺英雄遲暮 提交于 2019-11-27 04:12:59
问题 I have a Sherlock Fragment Activity in which there are 3 Fragments. Fragment A, Fragment B, Fragment C are three fragments. I want to show a done option menu in Fragment B only. And the activity is started with Fragment A. When Fragment B is selected done button is added. @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if(!menusInflated){

PopBackStack but keep the first fragment in android

青春壹個敷衍的年華 提交于 2019-11-27 03:55:45
问题 I am working on fragment transaction, and the backstack is like this: fragA => fragB => fragC => fragD I would like to return to fragA after back fromn the fragD fragD => onBackPress => fragA So, I tried code like: getChildFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE); but it clear all the backstack , how can I keep the first fragment in the backstack? Thanks a lot 回答1: E.g. you can do following: add fragA without adding it to backStack. So it always be in

Android non-UI Fragment usage [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-11-27 02:35:47
问题 This question already has answers here : What is the use case for a Fragment with no UI? (5 answers) Closed 5 years ago . I am going through the Android documentation on Fragments . The layout that defines the UI of a Fragment may be defined in the layout of the Activity, in a separate .xml file or not at all. According to the documentation you can also use a fragment to provide a background behavior for the activity without presenting additional UI. Why would I need to use another Fragment

Default Activity not found in Android Studio

怎甘沉沦 提交于 2019-11-27 00:45:52
I just upgraded to Android Studio 0.2.8 and I am getting an error that says "Default Activity not found" when I try to edit the run configurations. When I launch Android Studio I get this error "Access is allowed from event dispatch thread only" The activity I am using is a fragment activity. So far I've tried rebuilding and invalidate caches/restart. Both were of no use. Please let me know what I can do to fix the problem. Micer In Android Studio, right click on the project and choose Open Module Settings . Then go to the Sources tab in your module, find the src folder, right click on it and