Tag: android-fragments

Android: What's wrong with my fragment transition animation?

I just need plain slide in and slide out animation for Fragment transition, below is my code: slide_in_left.xml: <?xml version=”1.0″ encoding=”utf-8″?> <set xmlns:android=”http://schemas.android.com/apk/res/android” android:shareInterpolator=”true”> <translate android:fromXDelta=”-100%” android:toXDelta=”0%” android:fromYDelta=”0%” android:toYDelta=”0%” android:duration=”700″> </translate> </set> slide_out_right.xml: <?xml version=”1.0″ encoding=”utf-8″?> <set xmlns:android=”http://schemas.android.com/apk/res/android” android:shareInterpolator=”false”> <translate android:fromXDelta=”0%” android:toXDelta=”100%” android:fromYDelta=”0%” android:toYDelta=”0%” android:duration=”700″> </translate> </set> the code I used: SomeFragment frag = SomeFragment.newInstance(foo); […]

Update selected state of navigation drawer after back press

Whats the proper way to handle the selected state of the navigation drawer after back press? I have a navigation drawer with n entries (in a listview) like the SDK sample in Android Studio. When i click on the navigation drawer entries i want them to be added to the back stack, so i can […]

How to use Fragments in Android

EDIT ::: Please refer to my answer below… Question::: I am very new to using Fragments in Android and I am completely messed up. I am just trying to build a simple sample application that uses Fragments. My scenario is, I have two fragments in my main activity. The first fragment has an edittext and […]

Why does Kit Kat require the use of the isValidFragment?

Ever since KitKat was released, I’ve noticed a whole bunch of my apps updating with “Fixing a crash in Kit Kat”. Recently when I released my own app, I figured out the likely source of that is the new “isValidFragment” requirement for using preference activities. I haven’t been able to get anyone, however, to explain […]

Getting “Fragment did not create a view” after adition of other Fragment without UI

I’m having a really weird problem. I have a common fragment that is added in almost every activity of my app. This fragment shows a small version of the player bar. So it listens some broadcasts to update the current music’s name and has some controls, like play/pause. Like I said, I add this fragment […]

Fragment back stack does not work when extending AppCompatActivity

I’m using the new AppCompatActivity introduced in the AppCompat library version 22.1. When I extend this Activity, the hardware back button no longer pops the back stack of my Fragments, it closes the Activity instead. Here is how I’m changing fragments in my activity: public void changeFragment(Fragment f) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.fragment_holder, f); […]

How to call fragment from an activity in android?

I am working on android fragments. In my app I am getting an issue with activity and fragment. i.e I created a button in fragment1 and called an activity1 in that button click. Again in activity1 I created another button and called activity2. Now from activity2 I called activity1 and from activity1 I am trying […]

Android Fragment Tabs Example

I am currently working on 2.3 version of android and I want to switch my app to 4.0 version but the TabActivity is deprecated. So I was looking for working example of FragmentTabs but I am not able to find one. Can anyone help?

Adding a fragment to a dialog

I would like to add a fragment to a dialog (it can be either a DialogFragment or a regular Dialog). How do I do that? Here’s my DialogFragment: public class MyDialogFragment extends DialogFragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MyDialogFragment2 dialog = new MyDialogFragment2(); View v = inflater.inflate(R.layout.news_articles, container, false); getActivity().getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, […]

Set new layout in fragment

I’m trying to change the layout of a fragment during runtime under a particular condition. The initial layout in inflated within the onCreateView(): @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.cancel_video, null); } Then sometime later within the fragment code I would like to replace the initial layout with some other […]

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