我正在显示一个带有编辑文本的对话框并像这样设置输入类型十进制
**final EditText input = new EditText(context);
input.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);**
如果我使用默认的 alert.setPositiveButton 和setNegativeButton点击监听器,它的输入类型工作正常。但是当我使用
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { }
然后它的输入不起作用。下面是我的代码完整代码
package com.Dialogs;
public class GetSalesTaxPopUp {
Context context;
private AlertDialog dialog;
public void getSalesTax(Context context2){
this.context = context2;
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Sales Tax");
alert.setMessage("Enter Tax");
// Set an EditText view to get user input
final EditText input = new EditText(context);
input.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
dialog = alert.create();
dialog.show();
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String salestax = input.getText().toString();
if(!salestax.equals("")){
Toast.makeText(context, salestax, Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(context, "Enter Sales Tax", Toast.LENGTH_SHORT).show();
}
}
});
dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!MyPreferences.getMyPreference("GetSalesTax", context).equals("")){
dialog.dismiss();
}
else
Toast.makeText(context, "Enter Sales Tax First", Toast.LENGTH_SHORT).show();
}
});
// alert.show();
}
}
请指导我在哪里做错了。任何帮助表示赞赏。