I try to create tabs with ListFragment in it. I've tried several different appoaches but neither of them works. I don't know how to set container for ListFragment obkect properly. Here is java code.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabOne = actionBar.newTab().setText("ONE");
ActionBar.Tab tabTwo = actionBar.newTab().setText("TWO");
tabParkCinema.setTabListener(new tabListener());
tab28Cinema.setTabListener(new tabListener());
actionBar.addTab(tabOne);
actionBar.addTab(tabTwo);
}
protected class tabListener implements ActionBar.TabListener {
ParkFragment firstFragment;
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
switch (tab.getPosition()){
case 0:
if (firstFragment == null){
firstFragment = new ParkFragment();
System.out.println("initialized");
ft.add(R.id.cont, firstFragment,"FIRST");
}
else{
ft.attach(firstFragment);
}
break;
case 1:
if (firstFragment == null){
firstFragment = new ParkFragment();
ft.add(R.id.cont,firstFragment,"SECOND");
}
else{
ft.attach(firstFragment);
}
break;
}
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
};
public class ParkFragment extends ListFragment {
private ArrayList<Cinemas> cinema;
private CinemasAdapter cinemaAdapter;
private View v;
//private ListView list;
@Override
public View onCreateView(LayoutInflater in, ViewGroup gr, Bundle savedInstanceState) {
v = in.inflate(R.id.listing1, gr,false);
super.onActivityCreated(savedInstanceState);
cinema = new Handler().handle();
cinemaAdapter = new CinemasAdapter(MainActivity.this, R.layout.movie_data_row, cinema);
setListAdapter(cinemaAdapter);
return gr;
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
Cinemas movie = cinemaAdapter.getItem(position);
Intent intent = new Intent (MainActivity.this, More.class);
intent.putExtra("Cinemas", movie);
intent.putExtra("data", movie.getBitmap());
Bundle translateBundle =
ActivityOptions.makeCustomAnimation(MainActivity.this,
R.anim.slide_in_left, R.anim.slide_out_left).toBundle();
startActivity (intent, translateBundle);
}
}
}
And activity_main.XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cont"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id = "@+id/listing1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
Thank you for reading, any help will be appreciated!