0

下面是 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>       
4

2 回答 2

0

添加android:background="?androind:activatedBackgroundIndicator"到您的RelativeLayoutinR.layout.layout_for_cursor将为CHOICE_MODE_MUTLIPLE.ListFragment

要捕获这些选定的事件,请覆盖该onListItemClick方法,您将从中得到position回报。从那里,使用position检索所需的条目。

于 2013-08-06T16:02:21.673 回答
0

您必须使用可检查的布局。这是一个可检查的相对布局的实现。

看这个例子: http: //www.marvinlabs.com/2010/10/29/custom-listview-ability-check-items/

于 2013-08-04T12:18:17.307 回答