Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. package com.example.miss.androidapptwo;
  2.  
  3. import android.content.Context;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8. import android.widget.Button;
  9. import android.widget.Toast;
  10. import android.app.Activity;
  11. import android.view.Menu;
  12. import android.widget.CheckBox;
  13. import android.widget.EditText;
  14. import android.widget.RadioButton;
  15. import android.widget.RatingBar;
  16. import android.view.View.OnClickListener;
  17. import android.widget.ToggleButton;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20. Context context;
  21. CharSequence text;
  22. int duration;
  23. Toast toast;
  24.  
  25. String check_box = "";
  26. String radio_button = "One";
  27. String toggle_button = "Off";
  28. String rating_bar = "0.0";
  29. String edit_text = "";
  30.  
  31. boolean fruit = false;
  32. boolean meat = false;
  33.  
  34.  
  35. @Override
  36. protected void onCreate(Bundle savedInstanceState) {
  37. super.onCreate(savedInstanceState);
  38. setContentView(R.layout.activity_main);
  39.  
  40. context = getApplicationContext();
  41. duration = Toast.LENGTH_SHORT;
  42.  
  43.  
  44. Button btn_text = (Button) findViewById(R.id.btn_txt);
  45. btn_text.setOnClickListener(new OnClickListener() {
  46.  
  47. @Override
  48. public void onClick(View v) {
  49.  
  50. text = "You Clicked Text Button";
  51. Toast toast = Toast.makeText(context, text, duration);
  52. toast.show();
  53. }
  54. });
  55.  
  56. RatingBar ratingBar = (RatingBar) findViewById(R.id.rbar_star);
  57. ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener(){
  58.  
  59. @Override
  60. public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
  61.  
  62. //TODO Auto-generated method stub
  63. rating_bar = String.valueOf(rating);
  64.  
  65. }
  66. });
  67. }
  68.  
  69.  
  70. @Override
  71. public boolean OnCreateOptionsMenu(Menu menu) {
  72. getMenuInflater().inflate(R.menu.main, menu);
  73. return true;
  74. }
  75.  
  76. public void doButtonTextImage(View v) {
  77. text = "You Clicked Image Button";
  78. toast = Toast.makeText(context, text, duration);
  79. toast.show();
  80. }
  81. public void doImageButton(View v){
  82. text = "You Clicked Image Button";
  83. toast = Toast.makeText(context, text, duration);
  84. toast.show();
  85. }
  86. public void doCheckBox(View v) {
  87. boolean checked = ((CheckBox) v).isChecked();
  88. switch (v.getId()) {
  89. case R.id.cbx_fruit:
  90. if (checked) {
  91. fruit = true;
  92. } else {
  93. fruit = false;
  94. }
  95. break;
  96. case R.id.cbx_fruit:
  97. if (checked) {
  98. meat = true;
  99. } else {
  100. meat = false;
  101. }
  102. break;
  103. }
  104. if (fruit && meat) {
  105. check_box = "Fruit and Meat";
  106. } else if (fruit) {
  107. check_box = "Fruit";
  108. } else if (meat) {
  109. check_box = "Meat";
  110. } else {
  111. check_box = "No selection";
  112. }
  113. }
  114.  
  115. public void doRadioButton(View v) {
  116. boolean checked = ((RadioButton) v).isChecked();
  117. switch (v.getId()) {
  118. case R.id.rbtn_one:
  119. if (checked) ;
  120. radio_button = "One";
  121. break;
  122. case R.id.rbtn_two:
  123. radio_button = "Two";
  124. break;
  125. case R.id.rbtn_three:
  126. radtio_button = "Three";
  127. break;
  128. }
  129. }
  130.  
  131. public void doToggleButton(View v {
  132. boolean on = ((ToggleButton) v).isChecked();
  133. if (on) {
  134. toggle_button = "On";
  135. } else {
  136. toggle_button = "Off";
  137. }
  138. }
  139.  
  140. public void doButton (View v) {
  141. EditText etxt_msg = (EditText) FindViewById(R.id.etxt_msg);
  142. edit_text = etxt_msg.getText().toString();
  143. text = "Check Box: " +checked_box +"\n";
  144. text. text.toString() + "Radio Button: " +radio_button + "\n";
  145. text. text.toString() + "Toggle Button: " +toggle_button + "\n";
  146. text. text.toString() + "Rating Bar: " +rating_bar + "\n";
  147. text. text.toString() + "Edit Text: " +edit_text;
  148. text. text.toString() + edit_text;
  149. toast = toast.makeText(context, text, duration);
  150. toast.show();
  151.  
  152.  
  153.  
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement