单击单选按钮时尝试获取值

时间:2014-09-28 21:08:40

标签: android

@Override
protected void onCreate(Bundle savedInstanceState) {

    String value = ((radio1) findViewById).getText().toString();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pizzatype);

    Intent intent = new Intent(Pizzatype.this, Overview.class);
    intent.putextra("Bbread","Brown Bread");
    startActivity(intent);
}

1 个答案:

答案 0 :(得分:0)

您的问题是您没有说出radiobutton的ID是什么

试试这个:

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pizzatype);
        RadioButton rButton = (RadioButton) findViewbyId(R.id.radiobutton)
        String rText = rButton.getText().toString()
        Intent intent = new Intent(Pizzatype.this, Overview.class);
        intent.putextra("Bbread","Brown Bread ");
        startActivity(intent);
}

并将RadioButton定义如下:

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