Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.lesson2;
- import androidx.annotation.RequiresApi;
- import androidx.appcompat.app.AlertDialog;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.DialogInterface;
- import android.content.res.ColorStateList;
- import android.graphics.Color;
- import android.os.Build;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.RatingBar;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- private EditText path;
- private Button button, button1, buttonAlert;
- private RatingBar bar;
- private TextView textShow;
- @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- addListenerOnButton();
- }
- public void addListenerOnButton() {
- path = findViewById(R.id.editText2);
- button = findViewById(R.id.Alert);
- button1 = findViewById(R.id.button3);
- buttonAlert = findViewById(R.id.Alert);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(MainActivity.this, "не та кнопка", Toast.LENGTH_LONG).show();
- button.setText("done");
- }
- }); //вот тут!!!!!
- bar = findViewById(R.id.ratingBar);
- textShow = findViewById(R.id.textView);
- bar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
- @Override
- public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
- textShow.setText("Значение" + String.valueOf(rating));
- }
- });
- button1.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Toast.makeText(MainActivity.this, path.getText(), Toast.LENGTH_SHORT).show();
- }
- }
- );
- buttonAlert.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
- builder.setMessage("Вы хотите закрыть приложение?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- finish();
- }
- })
- .setNegativeButton("no", new DialogInterface.OnClickListener() { //тут!!!!!!!! ну и в остальных моментах
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.setTitle("Закрытие приложения");
- alert.show();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement