Im a little bit confused by the support package android.support.v4.app
because
i implemented a class extending the android.support.v4.app.FragmentActivity
and noticed
that it has methods which are expecting android.app.FragmentTransaction
as a parameter.
Why arent they expecting android.support.v4.app.FragmentTransaction
instead?
I still didnt get the difference between Fragment
, DialogFragment
, FragmentManager
etc.
from the support package compared to the regular packages. When do i have to use what?
I implemented for example a DialogFragment
from the regular package and use it in all my
acitvities when i have to make an alert to the user. Unfortunately now i have to write
antother DialogFragment
implementing the supertype from the support package, because i got
some fragments which are using the implementations from the support package. I cant change
them because they arent from me.
public class DiagramsActivity extends FragmentActivity implements TabListener, OnPageChangeListener {
private ViewPager viewPager = null;
private FragmentPagerAdapter fragmentPager = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.fragmentPager = new DiagramsFragmentPagerAdapter(this.getSupportFragmentManager());
this.setContentView(R.layout.activity_diagrams);
this.viewPager = (ViewPager) this.findViewById(R.id.diagrams_pager);
this.viewPager.setOnPageChangeListener(this);
this.viewPager.setAdapter(this.fragmentPager);
this.actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
this.actionBar.addTab(actionBar.newTab().setText(this.getResources().getString(R.string.text_line)).setTabListener(this));
this.actionBar.addTab(actionBar.newTab().setText(this.getResources().getString(R.string.text_bar)).setTabListener(this));
this.actionBar.addTab(actionBar.newTab().setText(this.getResources().getString(R.string.text_scatter)).setTabListener(this));
this.actionBar.addTab(actionBar.newTab().setText(this.getResources().getString(R.string.text_pie)).setTabListener(this));
}
@Override
public void onTabSelected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {
this.viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {}
@Override
public void onTabReselected(Tab tab, android.app.FragmentTransaction fragmentTransaction) {}
@Override
public void onPageScrollStateChanged(int state) {}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {
this.actionBar.setSelectedNavigationItem(position);
}
private void performChooseDates() {
FragmentTransaction fragmentTransaction = this.getSupportFragmentManager().beginTransaction();
MeasureDataSelectionDialogFragment measureDataGetSelectionDialogFragment = new MeasureDataSelectionDialogFragment();
measureDataGetSelectionDialogFragment.setCallback(this);
measureDataGetSelectionDialogFragment.show(fragmentTransaction, null);
}
}
The FragmentActivity
is from the support package. The methods from the TabListener
are expecting android.app.FragmentTransaction
so does my method performChooseDates()
. So i have an (from my point of view) ugly mix of support package and regular package. the Viewpager mentioned in the code
and the FragmentPagerAdapter are also from the support package because they dont exist in the regular package.