当我对 ListView 项目执行长按时,操作模式不会启动。ListView 的实现通过一个项目是相同的:
ListView listView = (ListView) view.findViewById(android.R.id.list);
listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
listView.setMultiChoiceModeListener(new NutritionMultiChoiceModeListener() {
@Override
public void deleteSelectedItems() {
for (int i = 0; i < componentAdapter.getCount(); i++) {
if (getListView().isItemChecked(i)) {
//Some actions
}
}
}
});
NutritionMultiChoiceModeListener 是自定义的 MultiChoiceModeListener,包含抽象方法 deleteSelectedItems(),调用删除。
这是 ListView 项目的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/backround_activated"
android:orientation="vertical" >
<Button
android:id="@+id/component_button"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/component_grams_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/ingredient_grams"
android:inputType="number" />
</LinearLayout>
当我执行长按时,我要么按下按钮,要么开始编辑文本。
项目中只有一个这样的地方。对于仅包含 TextView 的其他项目布局,一切正常。
请帮忙。