我在互联网上搜索如何执行新的很酷的android数据绑定在RadioGroup
,我没有找到关于它的一篇博客文章。如何在数据绑定的checkChanged事件绑定RadioGroup方法
它是一个简单的场景,基于所选的单选按钮,我想附加一个使用android数据绑定的回调事件。我没有找到任何方法在xml部分允许我定义回调。
喜欢这里是我的RadioGroup中:
<RadioGroup
android:id="@+id/split_type_radio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:checkedButton="@+id/split_type_equal"
android:gravity="center"
<!-- which tag ? -->
android:orientation="horizontal">
...
</RadioGroup>
如何附上处理方法将被称为上RadioGroup
的checkChnged
事件将触发使用数据绑定?
我一直在使用onClick
(不知道这是否是相同的)布局文件,并确定在活动方法尝试和布局文件中使用这个位于它:
<variable
name="handler"
type="com.example.MainActivity"/>
...
<RadioGroup
android:onClick="handler.onCustomCheckChanged"
.. >
而定义的方法onCustomCheckChanged
像这样:
public void onCustomCheckChanged(RadioGroup radio, int id) {
// ...
}
但是,它给我的编译错误:
Error:(58, 36) Listener class android.view.View.OnClickListener with method onClick did not match signature of any method handler.onCustomCheckChanged
我看到很多博客提到它可能与RadioGroup
但他们没有真的说如何。我如何处理data-binding
?
你看过[这个答案](http://stackoverflow.com/questions/38145783/cusom-event-attributes-in-android-bindings-apponmyevent/38197468#38197468)?我认为你可以做类似的事情。如果你仍然需要帮助。我会在周一看到它:) – yennsarah
@Amylinn谢谢你的链接。我真的很感激它:)我可以尝试,但我应该在xml中做什么属性?就像单选按钮中的checkChanged事件一样,没有任何让我提供方法的属性。如果我实际更改单选按钮(例如,将按钮重置为默认值),则“onClick”可能不起作用。 – kirtan403
我认为相应的属性应该是'app:onCheckedChangeListener'。 – yennsarah