出于某种原因,在创建列表视图后,new ArrayAdapter(getActivity(), R.layout.list_item, R.id.list_item, listContent)
将以黄色突出显示,并显示警告。有谁知道需要做些什么来解决这个警告?
未选中调用'ArrayAdapter(Context,int,int,T [])'作为原始类型'android.widget.ArrayAdapter'的成员
public class FragmentMainList extends android.support.v4.app.Fragment {
public FragmentMainList() {
}
ListView list_main;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
View v = inflater.inflate(R.layout.fragment_main_list, container, false);
String[] listContent = {
getActivity().getResources().getString(R.string.item_1),
getActivity().getResources().getString(R.string.item_2),
getActivity().getResources().getString(R.string.item_3)
};
list_main = (ListView)v.findViewById(R.id.list_main);
ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.list_item, R.id.list_item, listContent);
list_main.setAdapter(adapter);
return v;
}
}
答案 0 :(得分:1)
您的ArrayAdapter
是原始类型,因为它是模板化的,但您尚未指定类型。
要解决此问题:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.list_item, listContent);