首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >一次只选择一个RadioButton

一次只选择一个RadioButton
EN

Stack Overflow用户
提问于 2017-09-25 17:03:17
回答 1查看 1.5K关注 0票数 0

当我单击TextView引用时,我得到的是AlertDialog构建器,因为我显示的是带有RadioButtonsemployeesNames列表。现在,当我检查错误的Employee并想选择另一个employee时,应该取消检查错误的employee名称,通过选择一个Employee,应该启用ok Button

代码语言:javascript
运行
复制
delivery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            LayoutInflater inflater1 = (LayoutInflater) ct.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View v1 = inflater1.inflate(R.layout.activity_employees_list_for_pop_up, null);
            RadioButton employeechecked = (RadioButton) v1.findViewById(R.id.employeeChecked);
            final Button ok = (Button) v1.findViewById(R.id.do_ok);
            Button cancle = (Button) v1.findViewById(R.id.do_cancle);
            ok.setEnabled(false);
            listView = (ListView) v1.findViewById(R.id.employeePopUpList);
            employeePopUpAdapter = new EmployeePopUpAdapter(ct, employeeIdNameBeans);

            employeechecked.setOnCheckedChangeListener(new );


            listView.setAdapter(employeePopUpAdapter);

            AlertDialog.Builder builder;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder = new AlertDialog.Builder(ct, android.R.style.Theme_Material_Dialog_Alert);
            } else {
                builder = new AlertDialog.Builder(ct);
            }
            builder.setView(v1);
            builder.create().show();
            clearListView();
            update();
        }
    });

请帮助我的编码,不要张贴理论,我不能理解,我是一个初学者。

EN

回答 1

Stack Overflow用户

发布于 2017-09-25 17:35:30

您可以尝试RadioGroup而不是RadioButton。

代码语言:javascript
运行
复制
<RadioGroup
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/a"
    android:onClick="onRGClick">

    <RadioButton
        android:text="Normal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/a1" />

    <RadioButton
        android:text="Tidak normal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/a2" />

</RadioGroup>

并尝试选择和检索所选项的setOnCheckedChangeListener方法。

代码语言:javascript
运行
复制
radiogroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.a1) {
            // do your stuff
        } else if (checkedId == R.id.a2) {
            // do your stuff
        }
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46410498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档