问题描述
- Android新人求解:继承ListFragment的类没有setListAdapter()方法
-
package com.sudoku.ad.criminallntent;import android.app.ListFragment
import android.os.Bundle;
import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.ArrayList;/**
- Created by AD on 2015/8/4.
*/
public class CrimeListFragment extends ListFragment {
private ArrayList mCrimes;@Override
public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
getActivity().setTitle(R.string.crimes_title);
mCrimes = CrimeLab.get(getActivity()).getCrimes();
}
ArrayAdapter adapter =
new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,mCrimes);
setListAdapter(adapter);
}
在setListAdapter(adapter)那里显示有错啊!!!
- Created by AD on 2015/8/4.
解决方案
public void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
getActivity().setTitle(R.string.crimes_title);
mCrimes = CrimeLab.get(getActivity()).getCrimes();
setListAdapter(adapter);//放到这里来,需要放到方法里面
}
ArrayAdapter adapter =
new ArrayAdapter(getActivity(),android.R.layout.simple_list_item_1,mCrimes);
解决方案二:
Set方法应该在哦你create里面
时间: 2024-11-03 22:04:10