【问题标题】:Why View can't show the Group Radio Widget?为什么 View 不能显示 Group Radio Widget?
【发布时间】:2012-02-08 01:12:45
【问题描述】:

我在 XML 中添加了 Group Radio 小部件,但是当我调用 selectLevel() 时它没有显示在视图中。
我的代码:

public void selectLevel(){
     RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);  
     radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()  
        {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
                //---displays the ID of the RadioButton that is checked---

                Toast toast = Toast.makeText(getApplicationContext(), String.format("Level %d", checkedId), Toast.LENGTH_SHORT);
                toast.show();


            }
        });

【问题讨论】:

  • schemas.android.com/apk/res/android" >

标签: java android xml view


【解决方案1】:

我会将您的代码放在 onCreate 中,并将 RadioGroup 存储为您的活动字段。我认为这比调用另一个函数并且不能在它之外引用 RadioGroup 更有意义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2021-03-05
    • 1970-01-01
    • 2014-06-13
    • 2016-08-22
    相关资源
    最近更新 更多