亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

MainActivity 彈出窗口中的 AutoCompleteTextView

MainActivity 彈出窗口中的 AutoCompleteTextView

aluckdog 2023-03-17 16:38:07
在 MainActivity 中,我有帶有 AutoCompleteTextView 的彈出窗口并且它可以工作。我什至可以用它做一些工作人員 (egtextView.setText("New"))。但我擔心適配器,因為單擊 TextView 后沒有任何反應(沒有列表和鍵盤)。我認為這個問題是一致的:ArrayAdapter<String> adapter = new ArrayAdapter <String (customView.getContext(),android.R.layout.simple_dropdown_item_1line, countryNameList);特別是在第一個參數 - 上下文中。我不知道我應該把什么放在那里。我的代碼:public void steptwo() {        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);        View customView = inflater.inflate(R.layout.popup_observedproperty,null);        mPopupWindow = new PopupWindow(                customView,                LayoutParams.WRAP_CONTENT,                LayoutParams.WRAP_CONTENT        );        String[] countryNameList = {"India", "China", "Australia", "New Zealand", "England", "Pakistan"};        ArrayAdapter<String> adapter = new ArrayAdapter<String>(customView.getContext(),                android.R.layout.simple_dropdown_item_1line, countryNameList);        AutoCompleteTextView textView = (AutoCompleteTextView) customView.findViewById(R.id.autoCompleteTextView);        textView.setText("New");        textView.setAdapter(adapter);        if(Build.VERSION.SDK_INT>=21){            mPopupWindow.setElevation(5.0f);        }        mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);    }
查看完整描述

1 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

您需要使焦點可PopupWindow聚焦。要允許AutoCompleteTextView立即打開鍵盤,請將設置SoftInputMode為。PopupWindowSOFT_INPUT_STATE_ALWAYS_VISIBLE


public void steptwo() {

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);

        View customView = inflater.inflate(R.layout.popup_observedproperty,null);


        mPopupWindow = new PopupWindow(

                customView,

                LayoutParams.WRAP_CONTENT,

                LayoutParams.WRAP_CONTENT

        );


        String[] countryNameList = {"India", "China", "Australia", "New Zealand", "England", "Pakistan"};


        ArrayAdapter<String> adapter = new ArrayAdapter<String>(customView.getContext(),

                android.R.layout.simple_dropdown_item_1line, countryNameList);

        AutoCompleteTextView textView = (AutoCompleteTextView) customView.findViewById(R.id.autoCompleteTextView);

        textView.setText("New");

        textView.setAdapter(adapter);

        textView.setThreshold(1);


        if(Build.VERSION.SDK_INT>=21){

            mPopupWindow.setElevation(5.0f);

        }

        mPopupWindow.setFocusable(true);


        mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

        mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);

    }


查看完整回答
反對 回復 2023-03-17
  • 1 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號