我正在尝试将请求焦点设置为我的alertdialog框的edittext但它没有显示我的键盘 我添加了以下代码。我还将requestFocus()设置为edittext 但它没有展示任何东西。
mHolder.txt_lName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getmenuname = firstName.get(pos);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
alertDialog.setTitle("Select Quantity");
alertDialog.setMessage("Enter Quantity");
final EditText input = new EditText(mContext);
input.setInputType(InputType.TYPE_CLASS_NUMBER);
input.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
input.requestFocus();
input.setFocusable(true);
int maxLength = 4;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
input.setFilters(fArray);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
input.setLayoutParams(lp);
alertDialog.setView(input);
alertDialog.setPositiveButton("YES",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
/* int a = Integer.parseInt(mHolder.txt_lName.getText().toString());
int b = Integer.parseInt(input.getText().toString());
//int c = Integer.parseInt(taxEditText.getText().toString().toTrim());
int result = a + b ;*/
updatedquantity = input.getText().toString();
if (updatedquantity.matches("")) {
//Toast.makeText(mContext, "You did not enter a quantitiy", Toast.LENGTH_SHORT).show();
input.setError("You did not enter a quantitiy");
return;
} else {
//mHolder.txt_lName.setText(updatedquantity);
getupdateQuantity(getmenuname);
((DisplayActivity) mContext).displayData();
dialog.cancel();
}
}
});
alertDialog.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
});
} else {
mHolder = (Holder) child.getTag();
}
//mHolder.txt_id.setText(id.get(pos));
mHolder.txt_fName.setText(firstName.get(pos));
mHolder.txt_lName.setText(lastName.get(pos));
return child;
}
答案 0 :(得分:4)
创建一个像这样的自定义对话框
private void ShowDialog() {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(context);
View mView = layoutInflaterAndroid.inflate(R.layout.you_dialog_layout, null);
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(context);
alertDialogBuilderUserInput.setView(mView);
final AlertDialog alertDialogAndroid = alertDialogBuilderUserInput.create();
alertDialogAndroid.show();
final EditText edt_qty = (EditText) mView.findViewById(R.id.edt_subject);
Button cvSubmit = (Button) mView.findViewById(R.id.cvSubmit);
cvSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(edt_subject.getText().length()==0)
{
edt_qty.requestFocus();
edt_qty.setError("You did not enter a quantitiy");
} else {
//code
}
}
});
}
mHolder.txt_lName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ShowDialog();
}
});