我想在我的警告对话时向用户显示键盘,我已经尝试了
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(input.getWindowToken(), 0);
然而,键盘在对话框下显示。 我已经在清单中设置了我的活动:
<activity
android:name=".ActivityMain"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize"
/>
这是我用来生成对话框的代码
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>
但是在不同的活动中使用类似的代码(从AlertDialog.builder到(false);),我在点击edittext时显示键盘。我还尝试从edittext中删除我的listview,但没有任何反应。
答案 0 :(得分:0)
我遇到了同样的问题,您应该将android:windowSoftInputMode="adjustResize"
替换为"android:windowSoftInputMode="stateVisible"