用户输入应仅是“ \ u0030”或“ 0030”形式的unicode字符串。用户输入(toTrain)将传递给unicdoetochar方法,如果不是unicode,则返回错误。我想验证用户输入,以便使警报对话框重新出现在用户面前。
builder
.setCancelable(false)
.setPositiveButton("SUBMIT",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// get user input and set it to result
try {
toTrain = SymbolLib.unicodeToChar(userInput.getText().toString());
Toast.makeText(MainActivity.this, "Symbol: " + toTrain, Toast.LENGTH_SHORT).show();
}catch (Exception e){
Toast.makeText(MainActivity.this, "Please enter only unicode!", Toast.LENGTH_SHORT).show();
//alertdialog.show(); symbol cant be resolved
}
Toast.makeText(MainActivity.this, "Symbol: " + toTrain, Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
simpleswitch.setChecked(false);
}
});
// create alert dialog
final AlertDialog alertDialog = builder.create();