AutoCompleteTextView внутри всплывающего окна в MainActivity - PullRequest
0 голосов
/ 11 июля 2019

В MainActivity у меня есть всплывающее окно с AutoCompleteTextView, и оно работает.Я даже могу сделать некоторые сотрудники с этим (egtextView.setText («Новый»)).Но я обеспокоен адаптером, потому что после нажатия 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 Ответ

0 голосов
/ 11 июля 2019

Вам нужно сделать фокусировку PopupWindow.Чтобы AutoCompleteTextView мог сразу открыть клавиатуру, установите SoftInputMode для PopupWindow как SOFT_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);
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...