【问题标题】:Get ListItem id/position while clicking on RadioButton in that ListItem.单击该 ListItem 中的 RadioButton 时获取 ListItem id/位置。
【发布时间】:2014-08-08 12:50:03
【问题描述】:

我有 3 个RadioButtons 以及我的ListItem 中使用CursorAdapter 的一些文本。当我单击ListItem 中的任何RadioButton 时,我需要获取视图(ListItem)位置。因为,点击RadioButton 并不意味着我在点击ListItem。

【问题讨论】:

    标签: android android-listview android-listfragment android-radiogroup android-radiobutton


    【解决方案1】:

    在 bindView 或 newView 中:

    RadioButton radioButton = (RadioButton) view.findViewById(R.id.radio_button_id);
    radioButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Log.d(TAG, cursor.getPosition());
        }
    });
    

    还要确保游标在方法参数中声明为 final。

    【讨论】:

    • 我有 4 个列表项,每个都有 3 个单选按钮。当我将此解决方案应用于任何单选按钮时,它总是给我位置“3”,即最后一个的位置。
    • Thnx 很多,它的工作,我也只是把光标 final 的位置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多