安卓开发之radiobutton

image.png




    
        
        
    
    
        
        
        
        
        
        
        



package com.example.my_radiobutton;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public  void onRadio1Click(View view){
        //使用土司弹出信息:
        RadioButton radioButton = findViewById(view.getId());
        String string = (String)radioButton.getText();
        Toast.makeText(MainActivity.this, //要显示到哪一界面上
                string,                             //要显示的信息
                Toast.LENGTH_SHORT).show();        //显示的时间

    }


    public void onRadio2Click(View view) {
        RadioButton radioButton = findViewById(view.getId());
        String string = (String) radioButton.getText();
        Toast.makeText(MainActivity.this,   //要显示到哪一界面上
                string,                       //要显示的信息
                Toast.LENGTH_SHORT).show();  //显示的时间
    }
}

你可能感兴趣的:(安卓开发之radiobutton)