標籤:
public class LeftFragment extends Fragment{private ListView listView;@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {View view = inflater.inflate(R.layout.lesson_table_left, null);listView = (ListView) view.findViewById(R.id.listView);init();return view;}@Overridepublic void onActivityCreated(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onActivityCreated(savedInstanceState);}private void init() {List<String> items = new ArrayList<String>();for (int i = 0; i < 2; i++) {if(i == 0){items.add("課程表");}else{items.add("考試");}}ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_list_item_1, items);listView.setAdapter(adapter);}在Fragment中使用ListView不需要自訂的話,這樣就可以,如果想要自訂的話建議你還是使用ListFragment,在Fragment中我研究了很久也沒研究出來。
android,在fragment中使用listview,不使用listfragment