Tag: android-fragments

Show ProgressDialog in Fragment class

I am trying to show a ProgressDialog within a Fragment class. The following code just works within an Activity class but not for Fragment. Can somebody please help me on this, why this ProgressDialog implementaion just works within an Activity and not for a Fragment? private class ProcessUpdateProfile extends AsyncTask<String, String, JSONObject> { private ProgressDialog […]

How to replace fragment C with fragment A when back button is pressed?

My scenario : Activity 1 consists of Fragments A-> B-> C. All the fragments are added using this code : FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content, fragment, TAG); ft.addToBackStack(TAG); ft.commit(); Now, from fragment C, I want to directly return to Fragment A. Therefore, I’ve commented ft.addToBackStack(TAG) while adding Fragment C. So when […]

“Content view not yet Created” on Android Fragments

I am using Android Fragments with a viewpager setup. Basically there are 5 tabs you can swipe through. 4 of the 5 contain ListFragments that are populated by MySQL tables; this is done inside of an AsyncTask. When I swipe very fast I sometimes get this error: 09-01 07:54:01.243: E/AndroidRuntime(19706): FATAL EXCEPTION: main 09-01 07:54:01.243: […]

Unable to instantiate Fragment

Unable to instantiate fragment make sure class name exists, is public, and has an empty constructor that is public Is it because my Fragment is not a static class? Is it because my Fragment is an inner class? If I make my Fragment a static class, all my references to findViewById fail, which means a […]

onCreateOptionsMenu called after onResume on JB 4.2

I have the following fragment in my application: public class MyFragment extends SherlockListFragment implements LoaderManager.LoaderCallbacks<Cursor> { private MenuItem refresh = null; @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); setHasOptionsMenu(true); //….. // NPE here refresh.setActionView(R.layout.indeterminate_progress_action); getActivity().getSupportLoaderManager().initLoader(0, null, this); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.refresh_menu, menu); refresh = (MenuItem) menu.findItem(R.id.menu_item_refresh); } @Override public […]

How to properly hide&show the actionbar using the new design library API?

Background Suppose I have these elements in the activity: actionbar (actually a Toolbar) tabs (using TabLayout ) ViewPager, with fragments. each fragment has ListVIew/RecyclerView. I wish to have the same behavior as on many apps, that when scrolling, the action bar will hide or show. A perfect example for it is how the Play Store […]

Is it possible to pass arguments to a fragment after it's been added to an activity?

I know that when you’re first instantiating a fragment you can pass arguments using setArguments(Bundle) and retrieve them in the fragment using getArguments(). However, in my app I have fragments that will be detached and attached several times after they’ve been added to an activity. On re-attach, I may need to pass a fragment an […]

Sending Bundle with Fragment Transaction

Here is my code that is not working: // Sending bundle this way: String topUser = String.valueOf(scores.get(arg2)); Bundle data = new Bundle(); data.putString(“userprofile”, topUser); FragmentTransaction t = getActivity().getSupportFragmentManager() .beginTransaction(); SherlockListFragment mFrag = new ProfileFragment(); mFrag.setArguments(data); t.replace(R.id.main_frag, mFrag); t.commit(); // Retrieving this way: Bundle extras = getActivity().getIntent().getExtras(); userName = extras.getString(“userprofile”); Basically, the data isn’t received. Am […]

VideoView inside fragment causes black screen flicking

We have an Android application running on Android API 4.0. One of the activities has a layout that divides the screen in 2 parts. On the left side we have a static part with some buttons. On the right side we have a FrameLayout that will switch to the corresponding fragment depending on the button […]

Android : ViewFlipper Or ViewPager – Which is the better option?

I am getting stuck in one stage. I have a total of 20 to 25 images that should get animated like ViewPager does. Now on all the images I have onClick() events and I don’t know if I should work with ViewPager or ViewFlipper. I can implement both things, no issues here. What I Want […]

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