簡體   English   中英

Android KeyBoard未在AlertDialog中顯示

[英]Android KeyBoard doesn't show in AlertDialog

我已經嘗試了很多方法,但我無法在我的活動中顯示任何鍵盤。 鍵盤只是不顯示! 我在我的活動中有一個按鈕,當點擊時調用下面的方法創建一個對話框,里面有一個列表視圖,在頂部(在標題中)有一個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));

  • 嘗試使用onclicklisteners但效果相同......
  • 添加://edi.setFocusable(true); //edi.setFocusableInTouchMode(true); //edi.requestFocus();

*刪除edi.addTextChangedListener(filterTextWatcher); (誰知道可能有2個聽眾對他來說太多了)但是它不起作用但是看起來沒有用,我檢查了其他類似問題的鏈接,但要么沒有解決方案,要么對我不起作用:

以編程方式隱藏/顯示Android軟鍵盤

[ http://groups.google.com/group/android-developers/browse_frm/thread/17210d784766602d/d430c900a9c4019c?pli=1]

1 Android:焦點在EditText上時自動顯示軟鍵盤

任何建議都會受歡迎,或者我做錯了什么? 非常感謝,

我解決了!!!

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加構建器....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM