【问题标题】:No Multiple choice item seen in ListFagment在 ListFagment 中看不到多项选择项
【发布时间】:2013-08-02 19:09:41
【问题描述】:

下面是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() 方法上将选择模式设置为 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>       

【问题讨论】:

  • R.layout.layout_for_cursor 是什么样的?
  • 编辑帖子@Mike
  • 尝试将android:background="androind:activatedBackgroundIndicator"添加到RelativeLayout中的R.layout.layout_for_cursor
  • 添加这个会在 XML @Mike 中产生错误
  • @Mike 错误是 android:background 需要一个可绘制对象并且传递的是一个字符串

标签: android android-listview android-listfragment multiple-choice


【解决方案1】:

android:background="?androind:activatedBackgroundIndicator" 添加到R.layout.layout_for_cursor 中的RelativeLayout 将为ListFragmentCHOICE_MODE_MUTLIPLE 选项添加突出显示功能。

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-29
      • 2011-06-26
      • 2011-10-12
      • 1970-01-01
      • 2015-07-24
      • 2016-04-10
      相关资源
      最近更新 更多