碎片容器:
public class FragmentFolderList extends SherlockFragment{
protected AdapterFolderList _adapter;
protected ListView _listView;
protected View _view;
public static final String BACKSTACKCATEGORY = "backStackCat";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
_view = inflater.inflate(R.layout.fragment, container, false);
_listView = (ListView) _view.findViewById(R.id.list);
return _view;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
_adapter = new AdapterFolderList();
_listView.setAdapter(_adapter);
_listView.setOnItemClickListener(this);
}
protected void moveToDirectory(int where) {
FragmentDirectoriesList fragment = new FragmentDirectoriesList();
Bundle param = new Bundle();
param.putInt("position", where);
fragment.setArguments(param);
getActivity().getSupportFragmentManager().beginTransaction().add(R.id.fragment_annuaire, fragment).addToBackStack(BACKSTACKCATEGORY).commit();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
moveToDirectory(position);
}
}
布局 :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="4dp" >
</ListView>
</LinearLayout>