答案 0 :(得分:1)
在侦听器中检查是否选择了单选按钮:
findViewById(R.id.yourtextview).setVisibility(View.INVISIBLE);
和
findViewById(R.id.yourtextview).setVisibility(View.VISIBLE);
您可以选择INVISIBLE和GONE。
答案 1 :(得分:1)
以下是您的示例代码......
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
public class MainActivity extends Activity {
private RadioButton radioButton1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
radioButton1 = (RadioButton) findViewById(R.id.RadioButton1);
RadioGroup radioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(radioButton1.isChecked()) {
findViewById(R.id.textView).setVisibility(View.VISIBLE);
} else {
findViewById(R.id.textView).setVisibility(View.GONE);
}
}
});
}
}
这是xml布局:Main.xml
希望它能帮到你很多......
答案 2 :(得分:1)
public class _alefon_radio extends Activity implements OnCheckedChangeListener {
/** Called when the activity is first created. */
private TextView tx;
private RadioGroup rg;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tx = (TextView) findViewById(R.id.tvv);
rg = (RadioGroup) findViewById(R.id.rgroup);
rg.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
// for R.id.option1
case R.id.option1:
tx.setText("option one is checked");
//tx.setVisibility(0); //visible
break;
default:
tx.setText("");
//tx.setVisibility(4); //invisible
}
}
}
和布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/tvv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<RadioGroup
android:id="@+id/rgroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RadioButton
android:id="@+id/option1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<RadioButton
android:id="@+id/option2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<RadioButton
android:id="@+id/option3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
</RadioGroup>
</LinearLayout>
我使用编辑文本而不是设置visbile / invisible,但如果您想使用这种方式,我还包括visibilty控件(注释)。
我希望这就是你要找的东西。
祝你好运,