Tag: android-fragments

Fragment in round Wear watch turning black in emulator/watch

Im getting a black screen on my Android Wear round watch (on square it works). Both layouts show up OK in the Android Studio layout design. Project to test: https://bitbucket.org/powder366/motoblack Im using the following code: public class MyFragment extends Fragment { … @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View contentView = […]

Android findFragmentByTag returns null when debugging

Background: I am writing an android application with an activity that can be populated by one of a number of fragments. Relatively often, I need to pass a bundle of data to the active fragment so that it can update the UI accordingly. To get the current fragment, I call getfragmentManager().findFragmentByTag() and cast the returned […]

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?

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