Tag: android-fragments

Android Volley Null Pointer Exception

I’m attempting to convert a previously Activity-based tutorial to a Fragment, but I continue to run into the NullPointerException error on my Adapter. The tutorial is based on this and I have slimmed down the constructor for the Adapter because it used to be calling an Activity. There is one possible solution here but nobody […]

Implementing DatePicker in Fragment

I’am using Fragment which is an instance of Fragment and not of DialogFragment. I did google most of the search result shows how to use DialogFragment to have DatePicker. which isn’t working in my case because of type mismatch of Fragment and DialogFragment Any example or idea would be helpful Here is the Fragment Java […]

ListFragment Support Library GetSupportFragmentManager undefined

I have a list Fragment (importing the v4 support library, build target is 2.3.3 api 11) and the following problem in my code that was working fine when the target was 3.0 and I didn’t use the library. Fragment frag1 = new ExampleFragment(); FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.replace(R.id.contentframe, frag1); ft.commit(); Now I’m getting the compile […]

Bind service to FragmentActivity or Fragment?

Is it better to bind service to FragmentActivity: bindService(Intent, ServiceConnection, int); or to Fragment: getActivity().bindService(Intent, ServiceConnection, int); What is better practice?

java.lang.IllegalStateException: Can't change tag of fragment

Hi i am getting this error while using a pageViwer and Adapter to slide across 3 fragments. here is my pageAdapter public class FreedomPageAdapter extends FragmentPagerAdapter { private List<Fragment> listFragment; public FreedomPageAdapter(FragmentManager fm, List<Fragment> listFragment) { super(fm); this.listFragment = listFragment; } /* * (non-Javadoc) * * @see android.support.v4.app.FragmentPagerAdapter#getItem(int) */ @Override public Fragment getItem(int position) { […]

Could not find class 'android.widget.ThemedSpinnerAdapter'

I have ,in a fragment, a method call who open an AlertDialog when an user tap on an button, in that dialog I would like to show a Spinner with countries ( Spain, Italy, French….) My code for the spinner is the following: RestCountries restCountries = new RestCountries(); List<RestCountries.Datum> countries = restCountries.data; String mCities =””; […]

Complex Android UI design guidance needed (fragments)

I am developing an applications that is aimed at Tablets and Google TVs. It will be like many standard Google TV applications with a LeftNavBar and a top Search bar that is common to all application screens. It will look something like the following image: Main Screen The RED area will be different for all […]

Fragment's OnClickListener called after onDestroyView

I have an issue where ListFragment.onListItemClick is called after onDestroyView. I’m getting lots of error reports in the field (10-20 per day of ~1000 active users), but the only way I found to reproduce it is to hammer the back button while clicking all over the screen. Are hundreds of users really doing this? This […]

Unit tests NPE, when I add fragment custom transitions

OnBackPressed() test throws NPE when I added a custom transitions. It’s fine without the custom transitions. Why? THIS NPE ONLY HAPPENS IN UNIT TEST, NOT THE APP. class MyActivity { @Override public void onBackPressed() { ……. super.onBackPressed(); } private void putFragment(Fragment fragment) { String tag = fragment.getClass().getName(); FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); // TEST FAILED IF […]

Sometimes Fragment not attached to Activity (onCreateOptionsMenu)

Not sure why, but I get a few error-reports from an app in the playstore which have the message: java.lang.IllegalStateException: Fragment NewsOverViewFragment{4062e840} not attached to Activity at android.support.v4.app.Fragment.getResources(Fragment.java:601) at de.dala.simplenews.ui.NewsOverViewFragment.shouldUseMultipleColumns(NewsOverViewFragment.java:153) at de.dala.simplenews.ui.NewsOverViewFragment.updateMenu(NewsOverViewFragment.java:145) at de.dala.simplenews.ui.NewsOverViewFragment.onCreateOptionsMenu(NewsOverViewFragment.java:139) I already did a fix and check whether the fragment is attached to the activity but this is just “avoiding” the […]

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