The original idea was to combine fragment and Viewpager,
Then the whim, adding a ListView to the first fragment,
According to the suggestions on the Internet, extends Listfragment, followed by various error.
Carefully looked under, turned out to be mainactivity here:
1//Construction Adapter 2 list<fragment> fragments=new arraylist<fragment> (); 3 Fragments.add (New Fragment1 ()); 4 Fragments.add (New Fragment2 ()), 5 Fragments.add (New Fragment3 ()), 6 fpadapter adapter = new Fpadapter ( Getsupportfragmentmanager (), fragments);
Because it is
List<fragment>
Fragment1 with Listfragment naturally will error.
To modify the code in the Fragment1, add the ListView in the following way:
1 public class Fragment1 extends Fragment {2 3 private listview ListView; 4 5 6 public View Oncreatev Iew (Layoutinflater inflater, ViewGroup container, 7 Bundle savedinstancestate) {8 //TODO auto-generated method Stub 9 View view= inflater.inflate (R.LAYOUT.LAYOUT1, container, false); ListView = (ListView) View.findviewbyid (r.id.lv); arrayadapter<string> arrayadapter = new Arrayadapter<string> ( Getactivity (), Android. R.layout.simple_list_item_1,getdata ()); Listview.setadapter (Arrayadapter); return view;16 }17 Private list<string> getData () { list<string> data = new arraylist<string> (); 20 for (int i = 0;i <20;i++) { data.add (i+ ""); }23 return data;24}25 }
which
Android. R.layout.simple_list_item_1
is self-bringing, not defined.
This allows the ListView to display normally.
Add a ListView in fragment without using listfragment