下面是 ListFragment 的子类的代码。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SQLiteDatabase allDatabase2 = new TaskDatabaseManager(getActivity())
.getWritableDatabase();
Cursor allDetail = allDatabase2.rawQuery("Select "
+ TaskDatabaseManager.KEY_ROWID + ","
+ TaskDatabaseManager.TASK_TIMES + ","
+ TaskDatabaseManager.TASK_DESCRIPTION + " from "
+ TaskDatabaseManager.DATABASE_TABLE + " where "
+ TaskDatabaseManager.TASK_DATE + "= '"
+ LaunchActivity.selectedDate + "'", null);
String[] fromColumns = { TaskDatabaseManager.TASK_TIMES,
TaskDatabaseManager.TASK_DESCRIPTION };
int[] toView = { R.id.Time, R.id.TaskDescription };
allDetail.moveToFirst();
if (allDetail != null) {
setListAdapter(new SimpleCursorAdapter(getActivity(),
R.layout.layout_for_cursor, allDetail, fromColumns, toView,
0));
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater
.inflate(R.layout.fragment_layout, container, false);
// return super.onCreateView(inflater, container, savedInstanceState);
}
现在你可以看到我在 Overriden onViewCreated() 方法上将choiceMode 设置为ListView.CHOICE_MODE_MULTIPLE。
@Override
public void onViewCreated(View v, Bundle b) {
super.onViewCreated(v, b);
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}
但是在细节中仍然没有像多项选择那样可见。
下面是我的 fragment_layout.xml 的代码
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainContentLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawSelectorOnTop="true"
/>
</LinearLayout>
已编辑。这是 layout_for_cursor
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutForDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="58dp"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/TaskDescription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/Time"
android:layout_below="@+id/Time"
android:layout_marginTop="33dp"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>