package com.datong.diaplaymetrics;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private TextView textView;
private RadioGroup radioGroup;
private RadioButton radioButton, radioButton2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView) findViewById(R.id.textView);
radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
radioButton = (RadioButton) findViewById(R.id.radioButton);
radioButton2 = (RadioButton) findViewById(R.id.radioButton2);
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId){
case R.id.radioButton:
Toast.makeText(MainActivity.this,"radioButton",Toast.LENGTH_SHORT).show();
textView.setText(radioButton.getText());
break;
case R.id.radioButton2:
textView.setText(radioButton2.getText());
break;
}
}
});
}
}
android RadioGroup的使用
最新推荐文章于 2024-04-19 14:50:31 发布