以下是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>
答案 0 :(得分:0)
您必须使用可检查的布局。 这是一个可检查的relativelayout的实现。
请参阅此示例:http://www.marvinlabs.com/2010/10/29/custom-listview-ability-check-items/
答案 1 :(得分:0)
将android:background="?androind:activatedBackgroundIndicator"
添加到RelativeLayout
中的R.layout.layout_for_cursor
将为CHOICE_MODE_MUTLIPLE
的{{1}}选项添加突出显示功能。
要捕获这些选定的事件,请覆盖ListFragment
方法,然后您将从中获得onListItemClick
。从那里,使用position
检索所需的条目。