package com.example.dialogexample;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void showDialog(View view) {
        /*AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Poruka za dijalog").setTitle("Naslov za dijalog");
        builder.create();
        builder.show();*/

        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        LayoutInflater inflater = this.getLayoutInflater();

        View dialogView = inflater.inflate(R.layout.dijalog, null);

        builder.setView(dialogView).setPositiveButton("Uneto", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String ime = ((EditText)dialogView.findViewById(R.id.ime)).getText().toString();
                Toast.makeText(getApplicationContext(), ime, Toast.LENGTH_SHORT).show();
            }
        }).setNegativeButton("Odustani", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        builder.create();
        builder.show();


    }
}