ArrayAdapter 大小为 2 但 editText 为空

ArrayAdapter size is 2 but editText is null

为什么编辑文本为空

    BusDatabase = new BusesDatabase(getActivity());
    List<String> list = BusDatabase.getAllPlaces();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,list);
    AutoCompleteTextView editText = (AutoCompleteTextView)view.findViewById(R.id.autoComplete);
    editText.setAdapter(adapter);

由于您在片段中工作,因此需要通过片段的膨胀 rootView 来引用视图。所以:

View rootView = inflater.inflate(R.layout.fragment1, container, false);
EditText myEditText = rootView.findViewById(R.id.fragment_edit_text);

然后使用您的 myEditText