我把它放在onCreateView方法
中的DialogFragment里面时有空指针异常 AutoCompleteTextView med =(AutoCompleteTextView)getActivity().findViewById(R.id.new_autoCompleteT);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), android.R.layout.simple_list_item_1, item);
med.setAdapter(adapter);
答案 0 :(得分:0)
您似乎正在尝试从关联的View
中检索Activity
。您应该检查对getActivity()
的调用,也许它返回null,因为它尚未附加活动。从doc:
onActivityCreated (Bundle savedInstanceState)
方法
Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. It can be used to do final initialization once these pieces are in place, such as retrieving views or restoring state.