我想在某个点打开一个输入对话框,我可以在其输入后存储和使用它.
我在互联网上找到的所有例子都非常先进,我想它们并不像我想要的那样简单 – 我只需要类似于Java的东西:
String name = JOptionPane.showInputDialog("Enter your name");
保留输入以供以后计算对我来说也很重要.
先感谢您.
解决方法:
请尝试以下代码段. Main.this是活动参考.
// Set an EditText view to get user input
final EditText input = new EditText(Main.this);
new AlertDialog.Builder(Main.this)
.setTitle("Update Status")
.setMessage(message)
.setView(input)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
editable = input.getText();
// deal with the editable
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing.
}
}).show();
标签:java,android
来源: https://codeday.me/bug/20190614/1237383.html