Do fragments really need an empty constructor?

Yes they do. You shouldn’t really be overriding the constructor anyway. You should have a newInstance() static method defined and pass any parameters via arguments (bundle) For example: public static final MyFragment newInstance(int title, String message) { MyFragment f = new MyFragment(); Bundle bdl = new Bundle(2); bdl.putInt(EXTRA_TITLE, title); bdl.putString(EXTRA_MESSAGE, message); f.setArguments(bdl); return f; } … Read more

Fragment over another fragment issue

Set clickable property on the second fragment’s view to true. The view will catch the event so that it will not be passed to the main fragment. So if the second fragment’s view is a layout, this would be the code: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:clickable=”true” />

Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?

I thought Activity was deprecated No. So for API Level 22 (with a minimum support for API Level 15 or 16), what exactly should I use both to host the components, and for the components themselves? Are there uses for all of these, or should I be using one or two almost exclusively? Activity is … Read more

Update ViewPager dynamically?

When using FragmentPagerAdapter or FragmentStatePagerAdapter, it is best to deal solely with getItem() and not touch instantiateItem() at all. The instantiateItem()–destroyItem()–isViewFromObject() interface on PagerAdapter is a lower-level interface that FragmentPagerAdapter uses to implement the much simpler getItem() interface. Before getting into this, I should clarify that if you want to switch out the actual fragments … Read more

Android Fragment no view found for ID?

I was having this problem too, until I realized that I had specified the wrong layout in setContentView() of the onCreate() method of the FragmentActivity. The id passed into FragmentTransaction.add(), in your case R.id.feedContentContainer, must be a child of the layout specified in setContentView(). You didn’t show us your onCreate() method, so perhaps this is … Read more

Android Fragment onAttach() deprecated

Activity is a context so if you can simply check the context is an Activity and cast it if necessary. @Override public void onAttach(Context context) { super.onAttach(context); Activity a; if (context instanceof Activity){ a=(Activity) context; } } Update: Some are claiming that the new Context override is never called. I have done some tests and … Read more

Duplicate ID, tag null, or parent id with another fragment for com.google.android.gms.maps.MapFragment

The answer Matt suggests works, but it cause the map to be recreated and redrawn, which isn’t always desirable. After lots of trial and error, I found a solution that works for me: private static View view; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view != null) { ViewGroup parent = … Read more

Difference between add(), replace(), and addToBackStack()

One more important difference between add and replace is this: replace removes the existing fragment and adds a new fragment. This means when you press back button the fragment that got replaced will be created with its onCreateView being invoked. Whereas add retains the existing fragments and adds a new fragment that means existing fragment … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)