-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlertDialog mit Prompt für Eingaben.java
98 lines (74 loc) · 3.17 KB
/
AlertDialog mit Prompt für Eingaben.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package ch.nicolassauter.inputdialog;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick_button(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setTitle("Der Titel");
alertDialogBuilder.setMessage("Bla bla bla bla bal und bla.");
//**** EditText is a prompt field! *****************
final EditText editText = new EditText(this);
// Specify the type of input expected
editText.setInputType(InputType.TYPE_CLASS_TEXT);
// editText to alertDialogBuilder
alertDialogBuilder.setView(editText);
//**** End EditText prompt field *******************
// set dialog message
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// get user input and set it to result
// edit text
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
// create alert dialog
alertDialogBuilder.create().show();
}
}
// In Kotlin &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
package android.example.myapplication
import android.os.Bundle
import android.text.InputType
import android.util.Log
import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val aDB = AlertDialog.Builder(this)
.setTitle("Der Titel")
.setMessage("Bla bla bla")
//**** EditText is a prompt field! *****************
val eT = EditText(this)
eT.inputType = InputType.TYPE_CLASS_TEXT
aDB.setView(eT)
//**** End EditText prompt field *******************
// set dialog message
aDB
.setCancelable(false)
.setPositiveButton("OK") { dialog, id -> Log.d("TAG", "Result: ${eT.text}") }
.setNegativeButton("Cancel") { dialog, id -> dialog.cancel() }
.create().show()
}
}
// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&