android - ListView in fragment doesn't show -
i'm trying populate listview inside fragment, custom layout. when launch application content of listview not loaded (this obtained using array adapter). here code load listview:
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view = inflater.inflate(r.layout.activity_start, container, false); profilesdatabasehelper dbhelper = ac.getdbmanager(); profilemanagerdao dbdao = ac.getprofilemanagerdao(); //todo mettere profilehandler dentroo profileapp. profilehandler handler = new profilehandler(view.getcontext()); profile profile = handler.getcurrentprofile(); textview label = (textview) view.findviewbyid(r.id.labelvlm); label.settext("test"); if(handler!=null){ label.settext("ring volume: " + profile.getringvolume() + "max: " + handler.getmaxvolume(audiomanager.stream_ring)); label.append("\tvoice call volume: " + profile.getcallvolume() + " max: " + handler.getmaxvolume(audiomanager.stream_voice_call)); //manager.setstreamvolume(audiomanager.stream_voice_call, 5, 0); label.append("\twifi status: " + handler.iswifiactive()); } ringtone tone = ringtonemanager.getringtone(view.getcontext(), settings.system.default_ringtone_uri); if(tone!=null){ label.append("\n" + tone.gettitle(view.getcontext())); } seekbar bar = (seekbar) view.findviewbyid(r.id.ringtonevolumebar); bar.setmax(handler.getmaxvolume(audiomanager.stream_ring)); bar.setprogress(profile.getringvolume()); arraylist<string> profiles = ac.getprofilemanagerdao().getprofilenameslist(); if(profiles!=null){ log.d(tag, "list size: " + profiles.size()); listview profileslist = (listview) view.findviewbyid(r.id.profileslist); adapter = new profilesarrayadapter(view.getcontext(), r.layout.list_item, profiles); profileslist.setadapter(adapter); // list<string> testing = new arraylist<string>(); // testing.add("hey"); // testing.add("hey do"); // testing.add("hey it"); // testing.add("hey please"); // arrayadapter moviesadapter = new arrayadapter<string>(getactivity(),android.r.layout.simple_list_item_1, testing); // profileslist.setadapter(moviesadapter); //profileslist.seta } return view; }
here code of customadapter:
public class profilesarrayadapter extends arrayadapter<hashmap<string, integer>> { arraylist<hashmap<string, integer>> entries; int resourceid; context context; static class profileitemhandler { textview profileid; textview profilename; } public profilesarrayadapter(context context, int layoutresourceid, arraylist<hashmap<string,integer>> profiles) { super(context, layoutresourceid); this.context = context; this.resourceid = layoutresourceid; this.entries = profiles; } @override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; profileitemhandler handler = null; if(convertview==null){ layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(r.layout.list_item, parent, false); handler = new profileitemhandler(); handler.profileid = (textview) row.findviewbyid(r.id.profilename); handler.profilename = (textview) row.findviewbyid(r.id.profileid); row.settag(handler); } else { handler = (profileitemhandler) row.gettag(); } hashmap<string, integer> entry = this.getitem(position); for(string cur_entry: entry.keyset()){ handler.profileid.settext(cur_entry); handler.profilename.settext(entry.get(cur_entry)); } return row; }
}
and xml list item layout:
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <textview android:layout_height="wrap_content" android:id="@+id/profileid" android:text="textview" android:textappearance="?android:attr/textappearancelarge" android:layout_width="wrap_content"></textview> <textview android:text="textview" android:id="@+id/profilename" android:layout_width="wrap_content" android:layout_height="wrap_content"></textview> </linearlayout>
and here main layout:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_start" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".startactivity" > <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/labelvlm" android:text="@string/hello_world" /> <seekbar android:id="@+id/ringtonevolumebar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/labelvlm" android:layout_margintop="122dp" /> <listview android:id="@+id/profileslist" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignleft="@+id/ringtonevolumebar" android:layout_below="@+id/ringtonevolumebar" android:layout_margintop="68dp" > </listview> </relativelayout>
i don't receive error message, when launch application, no items shown in listview, , method getview of adapter never called. idea?
i found problem. inside constructor:
public profilesarrayadapter(context context, int layoutresourceid, arraylist<hashmap<string,integer>> profiles) { super(context, layoutresourceid); this.context = context; this.resourceid = layoutresourceid; this.entries = profiles; }
on first line, call super constructor wrong. in fact, correct call should be:
super(context, layoutresourceid, profiles);
with that, list populated correctly.
Comments
Post a Comment