Android: Displaying a list in a fragment -


i have existing fragment, in want display typical address kind of information street, city, pin , list of phone numbers.

to display list of phone numbers, added listview in addressfragment.xml:

<scrollview xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/content"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="vertical"         android:padding="16dp" >          <textview             android:id="@+id/txtstreetaddr"             style="?android:textappearancemedium"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:linespacingmultiplier="1.2"             android:text="default" />          <listview             android:id="@+id/phones"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_margin="0dp"             android:paddingleft="0dp" >         </listview>         </linearlayout> </scrollview> 

my fragment class:

        public class addressfragment extends fragment {             @override             public view oncreateview(layoutinflater inflater, viewgroup container,                     bundle savedinstancestate) {  viewgroup rootview = (viewgroup) inflater                 .inflate(r.layout.fragment_screen_slide_page, container, false);                  ((textview) rootview.findviewbyid(r.id.txtstreetaddr)).settext(                         "123, corner street");                  listview phonelistview = ((listview) rootview.findviewbyid(r.id.phones));                  arraylist<string> phnumbers = new arraylist<string>();                 phnumbers.add("4343534343");                 phnumbers.add("6767566766");                  arrayadapter<string> arrayadapter =                       new arrayadapter<string>(myapp.getappcontext(),android.r.layout.simple_list_item_1, phnumbers);                 // set adapter                 phonelistview.setadapter(arrayadapter);      return rootview;         } 

the phone list view not show on screen - why? there better way handle this?

i think forget inflate view in oncreateview(...)

view rootview= inflater.inflate(r.layout.your_layout, container, false); 

add oncreateview(...) should be

 public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {           view rootview= inflater.inflate(r.layout.your_layout, container, false);          ((textview) rootview.findviewbyid(r.id.txtstreetaddr)).settext(                 "123, corner street");          listview phonelistview =((listview) rootview.findviewbyid(r.id.phones);          arraylist<string> phnumbers = new arraylist<string>();         phnumbers.add("4343534343");         phnumbers.add("6767566766");          arrayadapter<string> arrayadapter =               new arrayadapter<string>(getactivity(),android.r.layout.simple_list_item_1, phnumbers);         // set adapter         phonelistview.setadapter(arrayadapter);       return rootview;   } 

Comments