Tag: android-fragments

Up Navigation (Action Bar's back arrow) is not working for fragments

I’ve drawer-layout as a base layout of my activity and I’m replacing two fragments on a frame present inside this drawer-layout. The first fragment is not added in fragment’s back stack. I’m displaying hamburger icon in my activity (I also want the drawer menu in my first fragment). In second fragment I disabled the hamburger […]

Android – How to dynamically change fragment layout

I have a tablet app with an about fragment which displays my company’s datas. I would like to change my layout dynamically with screen orientation while im on the page but i didn’t found how yet. If someone got the solution, thanks in advance

Best practice for tab navigation?

I am looking for best practice of using tab navigation with sherlock actionbar. What is the proper way of changing the fragments, and adding fragments to the backstack and clearing the back stack when another tab is selected. Are there any good examples or open source projects showing how to do it right?

NavigationDrawer fragment with ListView and custom Header

I’m having a problem and I can not solve it. In my app I have a navigation drawer defined as below: activity_main.xml <android.support.v4.widget.DrawerLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:id=”@+id/drawer_layout” android:layout_width=”match_parent” android:layout_height=”match_parent” > <!– As the main content view, the view below consumes the entire space available using match_parent in both dimensions. –> <FrameLayout android:id=”@+id/container” android:layout_width=”match_parent” android:layout_height=”match_parent” /> <!– […]

AndroidRuntimeException: requestFeature() must be called before adding content

This question already has an answer here: requestFeature() must be called before adding content 6 answers

Android ScrollView can host only one direct child

I have a onclick listener from the gallery that should clear all the rows inside the tableview, then add row/rows to a tableview inside a scrollview. The fragment should change on every button click. However I am getting: java.lang.IllegalStateException: ScrollView can host only one direct child. myactivity button listener TrackerFragment tf = (TrackerFragment) getFragmentManager().findFragmentById(R.id.tracker1); tf […]

How to run tests on an activities fragment

I am just starting out wih junit and the first issue I’m running into is, how should I test fragments? The activity being tested has 1 fragment which is the main layout. @Override protected void setUp() throws Exception { super.setUp(); Intent intent = new Intent(getInstrumentation().getTargetContext(), ActivityWelcome.class); startActivity(intent, null, null); FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); mFragmentWelcome = […]

How to handle multiple fragment interaction listeners in one Activity properly?

I have one Activity and six different Fragments attached to it. Each fragment has OnFragmentInteractionListener interface and activity implements all these listeners in order to receive callbacks. It looks a little messy, so I’m interested are there some patterns/ways to simplify this and make more elegant?

Fragment's onActivityCreated() is called after onDestroy() of Activity

Today I noticed a strange behavior in my application. It happens when I stop my application using Devices view from Eclipse. Can someone explain it? Why is onActivityCreated() of Fragment called even when Activity is already destroyed? MyHomeActivity contains two Fragments and similar log is generated for both. Here I am pasting logs for one […]

Why do you check for savedInstanceState == null when adding fragment?

In the fragment doc, in one of the example, they check for savedInstanceState == null when adding a fragment: public static class DetailsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { // If the screen is now in landscape mode, we can show the // dialog in-line with […]

Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.