【问题标题】:there is no text in radio buttons on screen屏幕上的单选按钮中没有文字
【发布时间】:2018-10-03 20:17:58
【问题描述】:

在这个程序中,我想在屏幕上显示带有房间名称的单选按钮

buttonList = new RadioButton[roomNames.length];
btGroup = (RadioGroup) findViewById(R.id.roomList);
RadioGroup.LayoutParams rprms;
for(int i = 0; i < roomNames.length; i++)
    {
        //buttonList[i] = new RadioButton(this);
        RadioButton tempBT = new RadioButton(this);
        System.out.println("room name number :"+ i + roomNames[i]);
        rprms= new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
        //tempBT.setText(roomNames[i].subSequence(0,roomNames[i].length()));
        //tempBT.setTextColor(0);
        tempBT.setId(i);
        buttonList[i] = tempBT;
        btGroup.addView(tempBT, rprms);
        //buttonList[i].setText(roomNames[i].subSequence(0,roomNames[i].length()));
        //buttonList[i].setTextColor(0);
        //btGroup.addView(buttonList[i], rprms);
    }
    for (int f = 0; f < btGroup.getChildCount(); f++) {
        ((RadioButton) btGroup.getChildAt(f)).setText(roomNames[f].subSequence(0,roomNames[f].length()));
        ((RadioButton) btGroup.getChildAt(f)).setTextColor(0);
    }

    //saving the chosen room name
    btGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){
        @Override
        public void onCheckedChanged(RadioGroup arg0, int selectedId) {
            for(int j = 0; j < buttonList.length; j++)
            {
                if(btGroup.getCheckedRadioButtonId() == buttonList[j].getId())
                {
                    roomNameSelected = roomNames[j];
                }
            }

        }
    });                                

但是当我运行这个程序时,我看到了单选按钮,但里面没有文字

【问题讨论】:

  • 会不会是因为setTextColor(0) 部分?试试setTextColor(Color.BLACK)
  • 哇,是的,它成功了!非常感谢!!!

标签: java radio-button android-studio-3.1


【解决方案1】:

代替

setTextColor(0);

试试

setTextColor(Color.BLACK);

【讨论】:

    猜你喜欢
    • 2022-11-06
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-19
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多