gpt4 book ai didi

java - 创建 ListView 后出现“取消选中调用”警告

转载 作者:行者123 更新时间:2023-11-30 01:57:48 28 4
gpt4 key购买 nike

出于某种原因,在创建我的 ListView 后 new ArrayAdapter(getActivity(), R.layout.list_item, R.id.list_item, listContent) 以黄色突出显示并出现警告。有谁知道需要做什么才能解决此警告?

Unchecked call to 'ArrayAdapter(Context, int, int, T[])' as a member of raw type '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;
}
}

最佳答案

你的 ArrayAdapter是原始类型,因为它是模板化的,但您尚未指定类型。

解决问题:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.list_item, R.id.list_item, listContent);

关于java - 创建 ListView 后出现“取消选中调用”警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31953247/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com