我尝试过很多种方法,但在我的活动中无法得到任何键盘。键盘不显示!在我的活动中有一个按钮,当单击该按钮时,调用下面的方法,在下面创建一个对话框,其内部和顶部(标题中)都有一个listview。
我希望用户在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>当对话框打开时,编辑文本接缝会获得焦点,它会改变颜色,而当我调试fovus状态时,会自动更改为true或false。
我已经尝试过但不起作用的事情:*删除cancel按钮*将焦点侦听器直接添加到同上的文本中,而不是list视图,但是它没有帮助*这段用于alertDialog: alertDialog: LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)的代码;
尝试使用onclicklisteners的effect...
*删除edi.addTextChangedListener(filterTextWatcher);(谁知道可能有两个侦听器对他来说太多),但它不起作用,但NOTHing似乎起作用了,我检查了其他有类似问题的链接,但要么根本没有解决方案,要么对我不起作用:
Programmatically Hide/Show Android Soft Keyboard
[http://groups.google.com/group/android-developers/browse_frm/thread/17210d784766602d/d430c900a9c4019c?pli=1]
1 Android: show soft keyboard automatically when focus is on an EditText
有什么建议是值得欢迎的,还是我做错了什么?非常感谢,
发布于 2011-09-02 10:02:02
我解决了!
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 +生成器..。
https://stackoverflow.com/questions/7281322
复制相似问题