Tag: android-fragments

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 […]

Exit animation not working; FragmentTransaction custom animation does not work for hide

I use show/hide to display a fragment that takes up part of the screen. For some reason when the fragment is shown the slide_in_left animation plays, but when the fragment is being hidden there is no animation, the fragment just disappears. I’ve tried using the slide_in_left animation for both exit and enter, this did not […]

How do I restore a previously displayed Fragment?

I’m using the compatibility package v4 in my project and I’m having an issue with keeping a Fragment around after it’s removed from view. I have my Activity displaying 2 fragments…a menu frame on the left, content pane on the right. The menu frame has 3 different menus (Fragments) that can be displayed. This is […]

Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference

I’m trying to implement sliding tab layout using android material design. But it gives me NullPointerException. Here is my code so far: MainActivity.java public class MainActivity extends ActionBarActivity { private Toolbar toolbar; private ViewPager pager; private SlidingTabLayout nLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_appbar); toolbar = (Toolbar) findViewById(R.id.app_bar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); NavigationDrawerFragment drawerFragment = […]

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