在MainActivity中,我弹出了AutoCompleteTextView,它可以正常工作。我什至可以为此做一些工作(例如textView.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);
}
答案 0 :(得分:0)
您需要使PopupWindow
更具针对性。要允许AutoCompleteTextView
立即打开键盘,请将SoftInputMode
的{{1}}设置为PopupWindow
。
SOFT_INPUT_STATE_ALWAYS_VISIBLE