我在androidhive中创建了一个使用Fragments的导航抽屉。现在我想在片段内创建一个3个选项卡,我已经尝试了所有但不能创建选项卡,请指导我创建选项卡。我会发布我的代码。
public class ViewGuestlist extends Fragment {
CalendarView calendar;//http://192.168.1.91/music_admin/display_menulist
public ViewGuestlist(){
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_community, container, false);
setHasOptionsMenu(true);
return rootView;
}
@Override
public void onCreateOptionsMenu(android.view.Menu menu,android.view.MenuInflater inflater) {
menu.findItem(R.id.action_settings).setTitle("Select Date");
super.onCreateOptionsMenu(menu, inflater);
};
/* @Override
public boolean onOptionsItemSelected(MenuItem item) {
//Toast.makeText(getActivity(), "hi..", Toast.LENGTH_SHORT).show();
Log.v("hi", "hi");
Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.calendar);
dialog.setTitle("Select Date");
calendar = (CalendarView)dialog.findViewById(R.id.calendar);
calendar.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view,int year, int month, int dayOfMonth) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(),dayOfMonth +"/"+month+"/"+ year,Toast.LENGTH_SHORT).show();
}
});
dialog.show();
return super.onOptionsItemSelected(item);
}*/
}
布局:
<?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">
<TextView
android:id="@+id/txtLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textSize="16dp"
android:text="Communities View"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtLabel"
android:src="@drawable/ic_communities"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"/>
</RelativeLayout>