2
我试图非常接近地遵循官方的Android指南CABforListView,但我还没有能够在我的ListView项目长按上激活上下文操作视图。如何在ListView中启用批处理上下文操作?
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadList(); // loads Cursor data and sets list adapter in AsyncTask
ListView listView = getListView();
listView.setLongClickable(true); // no effect
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
// implemention of MultiChoiceModeListener
});
}
// rest of the class
}
以下是我的list_row_item.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?android:attr/activatedBackgroundIndicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:longClickable="true"
android:paddingLeft="15dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<TextView
android:id="@+id/reminder_row_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/reminder_row_interval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/reminder_row_description"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Switch
android:id="@+id/switch_reminder_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/reminder_row_interval"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
<TextView
android:id="@+id/reminder_row_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/reminder_row_interval"
android:layout_below="@+id/reminder_row_interval"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
而且我activity_main.xml中:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
我一直在使用listView.setOnItemLongClickListener()
手动启动ActionMode尝试过,但同时已推出上下文动作模式我无法做多选,也没有教程/指南需要这样做。我错过了一些东西。
基本上,我想所见Jelly Bean中的闹钟实现的正是这种效果:
任何指针将不胜感激!
请问你'MultiChoiceModeListener'样子? – Luksprog
现在几乎没有。 'onCreateActionMode'膨胀了上下文菜单。 'onActionItemClicked'被设置为什么也不做。 'onItemCheckedStateChanged'基本上具有设置标题的完整性检查。但这些都不会发生。调试器证明它根本不被调用。 –
我正在使用SimpleCursorAdapter作为列表适配器。这可能是问题吗?也许我需要手动做我自己的动作模式。 –