[英]Keyboard not showing above Custom AlertDialog when user clicks on EditText
I'd like to show keyboard to the user when I my alertdialog ABOVE it, I've already tried with 我想在我的警报上面给用户显示键盘,我已经尝试过了
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
however, keyboard gets displayed UNDER the dialog. 但是,键盘会在对话框下显示。 I've already set my activity in manifest like this: 我已经在清单中设置了我的活动,如下所示:
<activity
android:name=".ActivityMain"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
/>
Here's the code I used to generate the dialog 这是我用来生成对话框的代码
public void createConstDialog(String[] textstring) {
AlertDialog.Builder builder =
new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
LayoutInflater inflater = this.getLayoutInflater();
final View dialogView = inflater.inflate(R.layout.dialog_editconstantformula, null);
builder.setView(dialogView);
builder.setTitle("Edit Values");
builder.setCancelable(false);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.activity_view_calculator_formula, R.id.constid, textstring);
lv = (ListView) dialogView.findViewById(R.id.list_view1);
final MyListAdapter myListAdapter = new MyListAdapter();
lv.setAdapter(myListAdapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, final int position, long viewId) {
mConstid = (TextView) view.findViewById(R.id.constid);
mConstid.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("touched", "" + position);
}
});
mConstvalue = (EditText) view.findViewById(R.id.constvaluez);
mConstvalue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d("touched", "" + position);
}
});
}
});
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
for (int i = 0; i < lv.getCount(); i++) {
View wantedView = lv.getChildAt(i);
mConstvalue = (EditText) wantedView.findViewById(R.id.constvaluez);
String letter = lv.getItemAtPosition(i).toString();
String value = mConstvalue.getText().toString();
Log.d("touched", (letter + "valore: " + mConstvalue.getText().toString()));
mFormulaEditText.setText(mFormulaEditText.getText().toString().replaceAll(letter, value));
}
dialog.dismiss();
}
});
builder.show();
}
R.layout.dialog_editconstantformula
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/list_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="1dp"
android:padding="10dp" >
</ListView>
</LinearLayout>
But with a similar code in a different activity, (from AlertDialog.builder to (false);), I get Keyboard showing on click on an edittext. 但是在不同的活动中使用类似的代码(从AlertDialog.builder到(false);),我会在点击编辑文本时显示键盘。 I also tried to remove my listview from the edittext, however nothing happens. 我也尝试从edittext中删除我的listview,但没有任何反应。
我有同样的问题,你应该用“ android:windowSoftInputMode="adjustResize"
替换"android:windowSoftInputMode="stateVisible"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.