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作爲列表適配器。這可能是問題嗎?也許我需要手動做我自己的動作模式。 –