Skip to content

Instantly share code, notes, and snippets.

@bigdragon1977
Created July 25, 2016 09:41
Show Gist options
  • Save bigdragon1977/e9dc6bdd9f50751d91a66d9a476def6b to your computer and use it in GitHub Desktop.
Save bigdragon1977/e9dc6bdd9f50751d91a66d9a476def6b to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" android:background="#0077cc">
<FrameLayout
android:id="@+id/menuPlace"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true" />
<FrameLayout
android:id="@+id/place3"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/menuPlace" />
<FrameLayout
android:id="@+id/place2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/place3" />
<FrameLayout
android:id="@+id/place1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_toRightOf="@id/place2" />
</RelativeLayout>
public class FragAccordion extends FragmentActivity {
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.frag_fragaccordion);
getSupportFragmentManager().beginTransaction()
.add(R.id.menuPlace, new Fragment0()).commit();
}
public static class Fragment0 extends ListFragment {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FragmentActivity fa = getActivity();
if (position == 0) {
FragmentTransaction ft = fa.getSupportFragmentManager()
.beginTransaction();
ft.setCustomAnimations(android.R.anim.slide_in_left,
android.R.anim.slide_out_right);
ft.add(R.id.place3, new Fragment1()).commit();
} else if (position == 1) {
FragmentTransaction ft = fa.getSupportFragmentManager()
.beginTransaction();
ft.setCustomAnimations(android.R.anim.slide_in_left,
android.R.anim.slide_out_right);
ft.add(R.id.place2, new Fragment2()).commit();
} else {
FragmentTransaction ft = fa.getSupportFragmentManager()
.beginTransaction();
ft.setCustomAnimations(android.R.anim.slide_in_left,
android.R.anim.slide_out_right);
ft.add(R.id.place1, new Fragment3()).commit();
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_list_item_1, new String[] {
"Fragment1", "Fragment2", "Fragment3" }));
}
}
public static class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Button b = new Button(getActivity());
b.setBackgroundColor(Color.GREEN);
b.setText("Fragment 1");
return b;
}
}
public static class Fragment2 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Button b = new Button(getActivity());
b.setBackgroundColor(Color.BLUE);
b.setText("Fragment 2");
return b;
}
}
public static class Fragment3 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Button b = new Button(getActivity());
b.setBackgroundColor(Color.BLACK);
b.setText("Fragment 3");
return b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment