Tag: android-fragments

How to pass a value from one Fragment to another in Android?

I am a newbie to Fragments. I want to pass a String value from one Fragment to another. how to do this? I have called my Fragments in the following way. please guide me step by step. String cid = id.getText().toString(); Fragment fr = new FriendFragment(); android.app.FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.content_frame, fr); ft.commit();

How to Remove Fragment from FragmentPagerAdapter?

I know there are some topics about this here already but I could not find a solution which I could get to work for my case. I have a working sliding gallery using a custom FragmentActivity and FragmentPagerAdapter which holds a list of Fragments. Within the FragmentActivity is a ImageView “delete”. If clicked the function […]

Change viewpager fragment by a buttonClick

I’m trying to change the viewpager fragment by clicking on a button. I have 5 fragments, each fragment has it’s own xml file (frag1.xml, frag2.xml, and so on). Every fragment has it’s 5 buttons that should go to other pages of the viewpager. But the problem is how do I check in the FragmentPageAdapter which […]

Adding PlaceAutocompleteFragment to fragment throws error

I have implemented PlaceAutocompleteFragment in activity and is working successfuly. But how to implement the same in fragment in android? I have implemented placeautocomplete fragment like this PlaceAutocompleteFragment autocompleteFragment1 = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment1); Error I am getting is Incovertible types;cannot cast ‘android.support.v4.app.Fragment’ to com.google.android.gms.location.PlaceAutocompleteFragment ‘. XML LAYOUT IS <android.support.v7.widget.CardView android:layout_width=”match_parent” android:layout_height=”wrap_content” android:background=”@drawable/button_background” card_view:cardCornerRadius=”4dp” card_view:contentPadding=”0dp”> <fragment android:id=”@+id/place_autocomplete_fragment” […]

How can I show a DialogFragment using compatibility package?

I’ve tried to use DialogFragment on 3.0- devices, which not supports Fragment or DialogFragment by SDK level. So, I decided to use Android compatibility library, which supports Fragment. Then I created a DialogFragment class that extends android.support.v4.app.DialogFragment. But…..When I tried to show my DialogFragment using DialogFragment.show(), I notified that show(FragmentManager, String) accepts first argument as […]

FragmentPagerAdapter getItem error with ListFragment

I’ve looked at quite a lot of code and can’t figure this out. http://developer.android.com/reference/android/support/v4/app/FragmentPagerAdapter.html It has to be something simple. I’m showing most of the code. The error is in the next section. public class MainActivity extends FragmentActivity implements ActionBar.TabListener { public static final int TAB_COUNT = 3; public static InputMethodManager inputManager; SectionsPagerAdapter mSectionsPagerAdapter; ViewPager […]

How do I call a specific PreferenceFragment from a PreferenceActivity?

I have a PreferenceActivity with several fragments: R.xml.preferences: (shortened for better readability): <?xml version=”1.0″ encoding=”utf-8″?> <preference-headers xmlns:android=”http://schemas.android.com/apk/res/android”> <header android:fragment=”fragments.Fragment1″ android:id=”@+id/fragment1″ […] /> <header android:fragment=”fragments.Fragment2″ android:id=”@+id/fragment2″ […] /> […] </preference-headers> SettingsActivity: public class SettingsActivity extends PreferenceActivity { @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preferences, target); } } This will show a list entry with fragments.Fragment1, fragments.Fragment2, […]

Action Bar Search View (Android) null error

I am not sure why it is appearing as null, if it has to do something with the fragment and the fragment title or the drawer, since it is on the main activity of where this fragment is being pulled up from. Here is my menu xml item: <?xml version=”1.0″ encoding=”utf-8″?> <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:app=”http://schemas.android.com/apk/res-auto” > […]

when android's isValidFragment() from PreferenceActivity gets called?

For some application on which I was working, for devices with API level 19 I’m getting exception Caused by: java.lang.RuntimeException: Subclasses of PreferenceActivity must override isValidFragment(String) to verify that the Fragment class is valid! com… has not checked if fragment com…$. is valid. Then, I found out that for those applications android frameworks protected boolean […]

How to implement onBackPressed() & intents in fragment?

I know that onBackPressed() is a method in activity but, I want to use the functionality in fragments such that when back button is pressed, it gets redirected to another activity via Intent. Is there any solution to this ? public class News_Events_fragment extends Fragment { ProgressDialog pd; ListView lv1; SharedPreferences sharedPreferences = null; int […]

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