Advertisement
Timur69

qqq

Apr 26th, 2020
551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 KB | None | 0 0
  1. package com.example.lesson2;
  2.  
  3. import androidx.annotation.RequiresApi;
  4. import androidx.appcompat.app.AlertDialog;
  5. import androidx.appcompat.app.AppCompatActivity;
  6.  
  7. import android.content.DialogInterface;
  8. import android.content.res.ColorStateList;
  9. import android.graphics.Color;
  10. import android.os.Build;
  11. import android.os.Bundle;
  12. import android.view.View;
  13. import android.widget.Button;
  14. import android.widget.EditText;
  15. import android.widget.RatingBar;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20.     private EditText path;
  21.     private Button button, button1, buttonAlert;
  22.     private RatingBar bar;
  23.     private TextView textShow;
  24.  
  25.     @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState) {
  28.         super.onCreate(savedInstanceState);
  29.         setContentView(R.layout.activity_main);
  30.         addListenerOnButton();
  31.     }
  32.  
  33.     public void addListenerOnButton() {
  34.         path = findViewById(R.id.editText2);
  35.         button = findViewById(R.id.Alert);
  36.         button1 = findViewById(R.id.button3);
  37.         buttonAlert = findViewById(R.id.Alert);
  38.         button.setOnClickListener(new View.OnClickListener() {
  39.             @Override
  40.             public void onClick(View v) {
  41.                 Toast.makeText(MainActivity.this, "не та кнопка", Toast.LENGTH_LONG).show();
  42.  
  43.                 button.setText("done");
  44.  
  45.             }
  46.         });                                //вот тут!!!!!
  47.         bar = findViewById(R.id.ratingBar);
  48.         textShow = findViewById(R.id.textView);
  49.         bar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
  50.             @Override
  51.             public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
  52.                 textShow.setText("Значение" + String.valueOf(rating));
  53.             }
  54.         });
  55.  
  56.         button1.setOnClickListener(new View.OnClickListener() {
  57.                                        @Override
  58.                                        public void onClick(View v) {
  59.                                            Toast.makeText(MainActivity.this, path.getText(), Toast.LENGTH_SHORT).show();
  60.  
  61.                                        }
  62.                                    }
  63.         );
  64.         buttonAlert.setOnClickListener(
  65.                 new View.OnClickListener() {
  66.                     @Override
  67.                     public void onClick(View v) {
  68.                         AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
  69.                         builder.setMessage("Вы хотите закрыть приложение?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
  70.                             @Override
  71.                             public void onClick(DialogInterface dialog, int which) {
  72.                                 finish();
  73.  
  74.                             }
  75.                         })
  76.                                 .setNegativeButton("no", new DialogInterface.OnClickListener() { //тут!!!!!!!! ну и в остальных моментах
  77.                                     @Override
  78.                                     public void onClick(DialogInterface dialog, int which) {
  79.                                         dialog.cancel();
  80.                                     }
  81.                                 });
  82.                         AlertDialog alert = builder.create();
  83.                         alert.setTitle("Закрытие приложения");
  84.                         alert.show();
  85.  
  86.                     }
  87.                 });
  88.     }
  89.  
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement