MainActivity 弹出窗口中的 AutoCompleteTextView

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

    }


aluckdog
浏览 93回答 1
1回答

精慕HU

您需要使焦点可PopupWindow聚焦。要允许AutoCompleteTextView立即打开键盘,请将设置SoftInputMode为。PopupWindowSOFT_INPUT_STATE_ALWAYS_VISIBLEpublic void steptwo() {&nbsp; &nbsp; &nbsp; &nbsp; LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);&nbsp; &nbsp; &nbsp; &nbsp; View customView = inflater.inflate(R.layout.popup_observedproperty,null);&nbsp; &nbsp; &nbsp; &nbsp; mPopupWindow = new PopupWindow(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; customView,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LayoutParams.WRAP_CONTENT,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LayoutParams.WRAP_CONTENT&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; String[] countryNameList = {"India", "China", "Australia", "New Zealand", "England", "Pakistan"};&nbsp; &nbsp; &nbsp; &nbsp; ArrayAdapter<String> adapter = new ArrayAdapter<String>(customView.getContext(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; android.R.layout.simple_dropdown_item_1line, countryNameList);&nbsp; &nbsp; &nbsp; &nbsp; AutoCompleteTextView textView = (AutoCompleteTextView) customView.findViewById(R.id.autoCompleteTextView);&nbsp; &nbsp; &nbsp; &nbsp; textView.setText("New");&nbsp; &nbsp; &nbsp; &nbsp; textView.setAdapter(adapter);&nbsp; &nbsp; &nbsp; &nbsp; textView.setThreshold(1);&nbsp; &nbsp; &nbsp; &nbsp; if(Build.VERSION.SDK_INT>=21){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mPopupWindow.setElevation(5.0f);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; mPopupWindow.setFocusable(true);&nbsp; &nbsp; &nbsp; &nbsp; mPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);&nbsp; &nbsp; &nbsp; &nbsp; mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER,0,0);&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java