本文介绍了无线电集团onclick事件没有发射,我怎么知道哪些选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是无线电集团,但 RadioGroup中 的onClick 事件不是射击和该方法 getCheckedRadiobuttonID()将返回。这里是我的布局的元素:

 < RadioGroup中
            机器人:ID =@ + ID / RG1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:方向=横向
            机器人:的onClick =onRGClick>
 

方法

 公共无效onRGClick(视图v){
Toast.makeText(这一点,测试,1000).show();
}
 

解决方案

这个问题可以通过解决以下

  RadioGroup中RG =(RadioGroup中)findViewById(R.id.radioGroup1);
        rg.setOnCheckedChangeListener(新OnCheckedChangeListener()
        {
            @覆盖
            公共无效onCheckedChanged(RadioGroup中组,诠释checkedId)
            {
                开关(checkedId)
                {
                案例R.id.radio0:
                    // 做某事
                    打破;
                案例R.id.radio1:
                    // 做某事
                    打破;
                案例R.id.radio2:
                    // 做某事
                    打破;
                }
            }
        });
 

或者

您可以使用自定义的ID,而不是默认的

  RadioGroup中RG =(RadioGroup中)findViewById(R.id.radioGroup1);
            rg.setOnCheckedChangeListener(新OnCheckedChangeListener()
            {
                @覆盖
                公共无效onCheckedChanged(RadioGroup中组,诠释checkedId)
                {
                    开关(checkedId)
                    {
                    案例R.id.male:
                        // 做某事
                        打破;
                    案例R.id.female:
                        // 做某事
                        打破;
                    案例R.id.other:
                        // 做某事
                        打破;
                    }
                }
            });
 

I'm using radio group but RadioGroup onClick event is not firing and the method getCheckedRadiobuttonID() is returning null. Here is the element in my layout:

   <RadioGroup
            android:id="@+id/RG1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:onClick="onRGClick" >

Method

public void onRGClick(View v) {
Toast.makeText(this, "Test ", 1000).show();
}
解决方案

This problem can be solved using the following

RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
        rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
        {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId)
            {
                switch(checkedId)
                {
                case R.id.radio0:
                    // TODO Something
                    break;
                case R.id.radio1:
                    // TODO Something
                    break;
                case R.id.radio2:
                    // TODO Something
                    break;
                }
            }
        });

Alternatively

You can use custom ids rather than default one

  RadioGroup rg = (RadioGroup) findViewById(R.id.radioGroup1);
            rg.setOnCheckedChangeListener(new OnCheckedChangeListener()
            {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId)
                {
                    switch(checkedId)
                    {
                    case R.id.male:
                        // TODO Something
                        break;
                    case R.id.female:
                        // TODO Something
                        break;
                    case R.id.other:
                        // TODO Something
                        break;
                    }
                }
            });

这篇关于无线电集团onclick事件没有发射,我怎么知道哪些选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 07:14