开发者

Android KeyBoard doesn't show in AlertDialog

开发者 https://www.devze.com 2023-04-02 03:56 出处:网络
I have tried so many ways but I just can\'t get the display any Keyboard in my activity. Keyboard just doesn\'t show!!! I have button in my activity that when clicked calls the method below which crea

I have tried so many ways but I just can't get the display any Keyboard in my activity. Keyboard just doesn't show!!! I have button in my activity that when clicked calls the method below which creates a dialog with a listview inside and on top (in the header) there is an edittext.

I would like the user to enter a letter in the dit text and the array adapter will be filtered and will show only the relevant results. So everything works fine EXCEPT that there is no keyboard shown so you can't enter any text in the dit text. Here is the code:

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();
}

In the manifest I have this for this activity:

<activity android:name="com.tresipunt.iturist.Ventas2"
        android:label="@string/ventas"
        android:screenOrientation="portrait"
        android:configChanges="keyboard">
    </activity>

The edittext seams to get the focu开发者_如何学JAVAs when the dialog opens it gets the color changed and when I debug the fovus state changes to true or to false accrodingly

The things I have tried and that don't work: * removing the cancel button * adding the focus listener to the dittext directly instead of the list view but it doesn't help * this code for alertDialog: alertDialog.requestFeature().addContentView(edi, new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

  • trying with onclicklisteners instead but same effect...
  • adding those: //edi.setFocusable(true); //edi.setFocusableInTouchMode(true); //edi.requestFocus();

*removing the edi.addTextChangedListener(filterTextWatcher); (Who knows maybe 2 listeners were too much for him) but it doesn't work but NOTHing seems to work and I have checked the other links with similar problem but either there isn't even a solution or it doesn't work for me:

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

Any advice would be welcome or is there something I am doing wrong? Thanks a lot,


I solved it!!!

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();

just have to use a simple dialog not AlerertDialog plus builder....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号