Advertisement
ANTAR_NANDI

SENSOR_DEMO.java

Jul 10th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. package com.example.sensor_demo;
  2. import android.hardware.Sensor;
  3. import android.hardware.SensorManager;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.RadioButton;
  8. import android.widget.RadioGroup;
  9. import android.widget.TextView;
  10. import android.widget.Toast;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13. TextView SelectTV;
  14. RadioGroup Radiogrpup;
  15. RadioButton sundRb, vibrationRb, SilentRb;
  16.  
  17.  
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_main);
  22.  
  23. SelectTV = findViewById(R.id.seectTv);
  24. Radiogrpup = findViewById(R.id.groupRadio);
  25. sundRb = findViewById(R.id.soundRb);
  26. vibrationRb = findViewById(R.id.vibrationRb);
  27. SilentRb = findViewById(R.id.silentRb);
  28. Radiogrpup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
  29. @Override
  30. public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
  31.  
  32. if (checkId == R.id.soundRb) {
  33. Toast.makeText(MainActivity.this, "Choise sound", Toast.LENGTH_SHORT).show();
  34. } else if (checkId == R.id.vibrationRb) {
  35. Toast.makeText(MainActivity.this, "Choise vibration", Toast.LENGTH_SHORT).show();
  36. } else if (checkId == R.id.silentRb) {
  37. Toast.makeText(MainActivity.this, "Choise silent", Toast.LENGTH_SHORT).show();
  38. }
  39.  
  40.  
  41. }
  42. });
  43.  
  44. }
  45.  
  46.  
  47. public void chosse(View view) {
  48. int selectedId= Radiogrpup.getCheckedRadioButtonId();
  49.  
  50. if (selectedId==sundRb.getId()) {
  51. SelectTV.setText("you choose sound option");
  52.  
  53. }
  54. else if (selectedId==vibrationRb.getId()){
  55. SelectTV.setText("you choose vibration option");
  56. }
  57. else if (selectedId==SilentRb.getId()){
  58. SelectTV.setText("you choose silent option");
  59.  
  60.  
  61. }}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement