Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Back button and Fragment - Animation Won't Work
    primarykey
    data
    text
    <p>I have a custom Back button included in my Android Application. My Custom animation when clicking the fragments is ok but it seems I can't apply animation when clicking my own back button or even the back button of android. I don't know how to fix it, I already included these code in my Activity Class but it seems not to work.</p> <pre><code> @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menuitem1: break; case R.id.menuitem2: super.onBackPressed(); overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); break; default: break; } return true; } </code></pre> <p>I also tried to override the onbackPressed method but it seems also not to work</p> <pre><code> @Override public void onBackPressed() { super.onBackPressed(); overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right); } </code></pre> <p>I don't know how to implement this one...Kindly help me wth this one because we are running out of time because of this. Thank you</p> <p>Waiting for positive responses.</p> <p><a href="http://content.screencast.com/users/junnel1001/folders/Jing/media/2a13fd01-f467-4889-ac21-743c188a0f67/2012-07-09_1032.png" rel="nofollow noreferrer">My Android Application Screencast http://content.screencast.com/users/junnel1001/folders/Jing/media/2a13fd01-f467-4889-ac21-743c188a0f67/2012-07-09_1032.png</a></p> <p>EDIT</p> <p>ok this is how I set up my Fragments</p> <p>In my main Activity:</p> <pre><code> public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ActionBar actionBar = getActionBar(); Drawable myIcon = getResources().getDrawable( R.drawable.header_bg ); actionBar.setSplitBackgroundDrawable(myIcon); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tabA = actionBar.newTab().setIcon(R.drawable.about); ActionBar.Tab tabB = actionBar.newTab().setIcon(R.drawable.sponsors); ActionBar.Tab tabC = actionBar.newTab().setIcon(R.drawable.map); ActionBar.Tab tabD = actionBar.newTab().setIcon(R.drawable.destination); Fragment aboutTab = new PhotosActivity(); Fragment sponsorTab = new SongsActivity(); Fragment mapTab = new HCCMapActivity(); Fragment DestinationTab = new DestinationActivity(); tabA.setTabListener(new MyTabsListener(aboutTab)); tabB.setTabListener(new MyTabsListener(sponsorTab)); tabC.setTabListener(new MyTabsListener(mapTab)); tabD.setTabListener(new MyTabsListener(DestinationTab)); actionBar.addTab(tabD, 0, true); actionBar.addTab(tabC, 1, false); actionBar.addTab(tabA, 2, false); actionBar.addTab(tabB, 3, false); } protected class MyTabsListener implements TabListener{ Fragment fragment; public MyTabsListener(Fragment fragment){ this.fragment = fragment; } public void onTabSelected(Tab tab, FragmentTransaction ft) { Log.i("Tab Position Now", Integer.toString( tab.getPosition())); if (myTabPosition &lt; 0){ ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); }else{ if (myTabPosition &gt; tab.getPosition()){ ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right); Log.i("Tab Position Before",Integer.toString( myTabPosition)); }else{ ft.setCustomAnimations(R.anim.slide_out_left, R.anim.slide_out_right); Log.i("Tab Position Before1",Integer.toString( myTabPosition)); } } myTabPosition = tab.getPosition(); ft.replace(R.id.fragment_place, fragment, null); // ft.commit(); } public void onTabUnselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub ft.remove(fragment); } public void onTabReselected(Tab tab, FragmentTransaction ft) { // TODO Auto-generated method stub } } </code></pre> <p>In one of my fragments Class:</p> <p>E.g destinationActivity</p> <pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ View view = inflater.inflate(R.layout.destination_layout, container, false); ArrayList&lt;Category&gt; category = new ArrayList&lt;Category&gt;(); ListView lv = (ListView)view.findViewById(android.R.id.list); category.add(new Category("Image", "Image Banner")); category.add(new Category("HISTORICAL TOURS", "Historical Desc")); category.add(new Category("CULTURAL TOURS", "Cultural Desc")); lv.setAdapter(new CategoryAdapter(getActivity(), R.layout.list_view, category)); lv.setClickable(true); super.setMenuVisibility (false); super.setHasOptionsMenu(false); return view; } @Override public void onListItemClick(ListView l, View v, int position, long id) { Log.i("FragmentList", "Item clicked: " + id); final FragmentTransaction ft = getFragmentManager().beginTransaction(); if (id == 1){ // ft.remove(fragment) ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_in_right); ft.replace(R.id.fragment_place, new ListLocationActivity(), null); ft.addToBackStack(null); ft.commit(); }else if (id == 2){ ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_in_right); ft.replace(R.id.fragment_place, new ListLocationActivity(), null); ft.addToBackStack(null); ft.commit(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload