我在userdialog中有3个edittext,动态设置它们。其中2个正确键入文本,但1在某些设备上没有(android 2.3.4)。已经尝试过来自EditText freezes/doesn't show text whilst typing的解决方案。
这是我的代码:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("Имя устройства");
LinearLayout layout = new LinearLayout(context);
//alertDialog.setMessage("Задайте имя устройства");
final EditText inputName = new EditText(MainActivity.this);
inputName.setInputType(InputType.TYPE_CLASS_TEXT);
inputName.setOnEditorActionListener(doneListener);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
layout.setOrientation(LinearLayout.VERTICAL);
lp.setMargins(20, 20, 20, 20);
layout.setLayoutParams(lp);
final EditText inputInv = new EditText(MainActivity.this);
inputInv.setInputType(InputType.TYPE_CLASS_NUMBER);
inputInv.setTextColor(Color.BLACK);
inputInv.setOnEditorActionListener(doneListener);
final EditText inputDepartment = new EditText(MainActivity.this);
inputDepartment.setInputType(InputType.TYPE_CLASS_TEXT);
inputDepartment.setOnEditorActionListener(doneListener);
final TextView name = new TextView(MainActivity.this); name.setText("Имя устройства"); //name.setLayoutParams(lp);
final TextView inv = new TextView(MainActivity.this); inv.setText("Инвентарный номер"); //inv.setLayoutParams(lp);
final TextView dep = new TextView(MainActivity.this); dep.setText("Департамент");// dep.setLayoutParams(lp);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
name.setTextColor(Color.WHITE);
inv.setTextColor(Color.WHITE);
dep.setTextColor(Color.WHITE);
}
layout.addView(name);
layout.addView(inputName);
layout.addView(inv);
layout.addView(inputInv);
layout.addView(dep);
layout.addView(inputDepartment);
alertDialog.setView(layout);
alertDialog.setPositiveButton("Продолжить",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) {
SharedPreferences.Editor editor = shPref.edit();
String name = inputName.getText().toString() + "-" + inputInv.getText().toString() + "-" + inputDepartment.getText().toString();
editor.putString("Name", name);
editor.commit();
createShortCut(name);
}
});
OnKeyListener okl = new OnKeyListener() {
@Override
public boolean onKey(DialogInterface arg0, int keyCode,
KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
System.exit(0);
}
return true;
}
};
alertDialog.setOnKeyListener(okl);
alertDialog.show();
doneListener正在关闭软键盘。没有它也不行。
答案 0 :(得分:0)
看起来像对话框中的一些软键盘的错误。 通过拒绝对话框并使用Activity来解决此问题。