Advertisement
Guest User

Untitled

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