I use below code to implement tabhost:
public class MyActivity extends FragmentActivity {
private FragmentTabHost mTabHost = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mylayout);
mTabHost = (FragmentTabHost) findViewById(R.id.tabHost);
mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent);
mTabHost.addTab(mTabHost.newTabSpec("A").setIndicator("A"), AFragment.class, null);
mTabHost.addTab(mTabHost.newTabSpec("B").setIndicator("B"), BFragment.class, null);
}
}
It contains 2 tabs, AFragment.class as below:
public class AFragment extends Fragment {
private MyAdapter MyAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_folder_base, container, false);
ListView ListV = (ListView)view.findViewById(R.id.listview);
FolderList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//How to implement to launnch another fragmentC under the same tab
}
});
...
MyAdapter = new MyAdapter(this.getActivity(), this.getContext());
ListV.setAdapter(MyAdapter);
return view;
}
}
I want to launch another fragment (FragmentC) when the item has been click, How can I implement it?
And how can I implement onBackPressed()
function in these Fragments?