Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.sensor_demo;
- import android.hardware.Sensor;
- import android.hardware.SensorManager;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- TextView SelectTV;
- RadioGroup Radiogrpup;
- RadioButton sundRb, vibrationRb, SilentRb;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- SelectTV = findViewById(R.id.seectTv);
- Radiogrpup = findViewById(R.id.groupRadio);
- sundRb = findViewById(R.id.soundRb);
- vibrationRb = findViewById(R.id.vibrationRb);
- SilentRb = findViewById(R.id.silentRb);
- Radiogrpup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
- if (checkId == R.id.soundRb) {
- Toast.makeText(MainActivity.this, "Choise sound", Toast.LENGTH_SHORT).show();
- } else if (checkId == R.id.vibrationRb) {
- Toast.makeText(MainActivity.this, "Choise vibration", Toast.LENGTH_SHORT).show();
- } else if (checkId == R.id.silentRb) {
- Toast.makeText(MainActivity.this, "Choise silent", Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- public void chosse(View view) {
- int selectedId= Radiogrpup.getCheckedRadioButtonId();
- if (selectedId==sundRb.getId()) {
- SelectTV.setText("you choose sound option");
- }
- else if (selectedId==vibrationRb.getId()){
- SelectTV.setText("you choose vibration option");
- }
- else if (selectedId==SilentRb.getId()){
- SelectTV.setText("you choose silent option");
- }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement