<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="@+id/drawer_layout"
android:background="#9999"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#336699"
android:layout_height="53dp" android:weightSum="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="옛 지도"
android:id="@+id/textView"/>
</LinearLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="385dp"
android:layout_height="match_parent"
android:background="#475369"
android:divider="#535975"
android:id="@+id/navigation_list"
android:dividerHeight="0.7dp"/>
</LinearLayout>
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(
R.layout.fragment_navigation_drawer, container, false);
mDrawerListView = (ListView) rootView.findViewById(R.id.navigation_list);
mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
});
mDrawerListView.setAdapter(new ArrayAdapter<String>(
getActionBar().getThemedContext(),
android.R.layout.simple_list_item_multiple_choice,
android.R.id.text1,
new String[]{
getString(R.string.title_map),
getString(R.string.title_friends),
"Test"
}));
mDrawerListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
return rootView;
}
像这样的onCreateView方法
当我直接在onCreateView方法中返回mDrawerListView时ListView有“CheckBox”
但是当我返回rootView(包含mDrawerListView)
时CheckBox消失了
setAdapter String []数组工作正常,但只有“复选框”的问题
如何在ListView中添加复选框?
private void selectItem(int position) {
mCurrentSelectedPosition = position;
new AlertDialog.Builder(getActivity())
.setTitle("Some Title")
.setMessage("some message")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when ok got clicked
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Some stuff to do when cancel got clicked
}
})
.show();
在SelectItem方法中我可以看到选择LOG它意味着选择监听器工作正常
First Pic : when return rootView (LinearLayout)
Second Pic : when return mDrawerListView(ListView in LinearLayout)