我已经为GridView ItemClickListener
尝试了以下实施,该项目编译正常,但当我点击GridView
项时,Toast
不显示我的消息,&# 39;错了?
Java点击处理程序
public class MultiChoiceActions {
public void onItemClick(View view, int position, List<FieldOption> objectList) {
boolean currentValue = objectList.get(position).isChecked();
objectList.get(position).setChecked(!currentValue);
Toast.makeText(view.getContext(), "!currentValue " + (!currentValue) , Toast.LENGTH_SHORT).show();
}
}
XML Layout EDITED
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="vm"
type="br.com.viewluck.viewmodel.MultiChoiceViewModel"/>
<variable
name="adapter"
type="br.com.viewluck.viewmodel.MultiChoiceAdapter"/>
<variable
name="actions"
type="br.com.viewluck.viewmodel.MultiChoiceActions"/>
</data>
<android.support.v7.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="2dp"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/txt_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{vm.fieldLabel}"
android:textSize="14sp"
android:textStyle="bold" />
<GridView
android:id="@+id/gd_multiple_choice"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="multipleChoice"
app:options="@{vm.objectList}"
app:OnItemClickListener="@{(parent, view, position,id)->actions.onItemClick(view, position, vm.answer)}"
android:numColumns="auto_fit" />
</android.support.v7.widget.LinearLayoutCompat>
</layout>
任何建议都表示赞赏!
答案 0 :(得分:1)
我猜你可能忘了将它从activity / fragment
绑定binding.setActions(listener)