package com.hanxia.duorougardon;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class myfragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.myfragment, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String[] data = { "my gardon", "sell%buy", "friends", "baike" };
ListView listView=(ListView) view.findViewById(R.layout.myfragment);
listView.setAdapter(new ArrayAdapter<String>(view.getContext(), android.R.layout.simple_list_item_1,data));
}
问题是出现在最后一句:
更改前:listView.setAdapter(new ArrayAdapter<>(view.getContext(), android.R.layout.simple_list_item_1,data));没有写明new ArrayAdapter<>的类型,报错提示更改为更改为1.7的一致神马的。
在网上搜到大神讲解:如下图,注意到,没有<String>,于是更改尝试,错误不见了!O(∩_∩)O哈哈~,图片来源好像是个美女大神的原创!感谢!
本文出自 “9545560” 博客,请务必保留此出处http://9555560.blog.51cto.com/9545560/1626217
原文地址:http://9555560.blog.51cto.com/9545560/1626217