我尝试了很多方法,但我无法在我的活动中显示任何键盘。键盘只是不显示!我在我的活动中有一个按钮,当点击时调用下面的方法创建一个对话框,里面有一个列表视图,在顶部(在标题中)有一个edittext。
我希望用户在dit文本中输入一个字母,数组适配器将被过滤,并仅显示相关结果。所以一切正常,除了没有显示键盘,所以你不能在dit文本中输入任何文字。这是代码:
private void buildDialog(final int cual) {
// dialog que va mostrar una lista de clientes o articulos
AlertDialog.Builder ab = new AlertDialog.Builder(this);
if(cual==1){
mAdapter2 = new EventAdapter(this, clientes);
}else if (cual==2){
mAdapter2=new EventAdapter(this, ventas);
}
lv2=new ListView(this);
edi=new EditText(this);
edi.setHint("empiece a escribir");
edi.addTextChangedListener(filterTextWatcher);
lv2.addHeaderView(edi);
lv2.setAdapter(mAdapter2);
lv2.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(v.equals(edi) && hasFocus==true){
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}
});
ab.setView(lv2);
alertDialog = ab.create();
alertDialog.setButton(getResources().getString(R.string.cancelar),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();
}
在清单中我有这个活动:
<activity android:name="com.tresipunt.iturist.Ventas2"
android:label="@string/ventas"
android:screenOrientation="portrait"
android:configChanges="keyboard">
</activity>
当对话框打开时,edittext接缝获得焦点,它会改变颜色,当我调试fovus状态变为true或为false时
我尝试过但不起作用的事情: *删除取消按钮 *直接将焦点监听器添加到dittext而不是列表视图,但它没有帮助 * alertDialog的此代码: alertDialog.requestFeature()。addContentView(edi,new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
*删除edi.addTextChangedListener(filterTextWatcher); (谁知道可能有2个听众对他来说太多了)但是它不起作用 但NOTHing似乎工作,我已检查其他类似问题的链接,但要么甚至没有解决方案或它不适合我:
Programmatically Hide/Show Android Soft Keyboard
1 Android: show soft keyboard automatically when focus is on an EditText
欢迎任何建议,或者我做错了什么? 非常感谢,
答案 0 :(得分:4)
我解决了!!!
Dialog dialog = new Dialog(this);
if(cual==1){
mAdapter2 = new EventAdapter(this, clientes);
} else if (cual==2){
mAdapter2=new EventAdapter(this, ventas);
}
lv2=new ListView(this);
edi=new EditText(this);
lv2.addHeaderView(edi);
lv2.setAdapter(mAdapter2);
dialog.setContentView(lv2);
dialog.setCancelable(true);
dialog.show();
只需要使用简单的对话框而不是AlerertDialog加构建器....