Your content must have a ListView whose id attribute is 'android.R.id.list' 【Android 报错】

周六,在APP中增加一个加载列表的功能时报错:

Your content must have a ListView whose id attribute is 'android.R.id.list'

初步定位问题发生在Fragment的onCreateView()方法中:

@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View v = inflater.inflate(R.layout.fragment_user_list, container, false);
		
		return v;
	}

其中,fragment_user_list是自定义的layout文件,里面的id确实不叫“list”, 怎么办?难道把id改成list?

想起之前做的几个APP,有关ListView的时候,都是稀里糊涂做完的,有的就是直接用调用默认的super.onCreateView()的,好像也没出什么问题,于是,修改一下,我就不用自定义的layout文件吧,用默认的super.onCreateView()吧,省事:

@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View v = super.onCreateView(inflater, container, savedInstanceState);
		
		return v;
	}

OK,问题解决。


你可能感兴趣的:(Your content must have a ListView whose id attribute is 'android.R.id.list' 【Android 报错】)