android - Custom adapter for list not working -
i have listview supposed lists style has been defined in custom adapter. but, when open listactivity
, blank activity.
adapter code:
public class alarmlistcustomadapter extends arrayadapter<string> { private final context context; private final string[] values; typeface light; public alarmlistcustomadapter(context context, string[] values, string font) { super(context, r.layout.alarmlist_layout); this.context = context; this.values = values; lite = typeface.createfromasset(context.getassets(), font); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); view rowview = inflater.inflate(r.layout.alarmlist_layout, parent, false); textview tv1 = (textview) rowview.findviewbyid(r.id.alarm_time); textview tv2 = (textview) rowview.findviewbyid(r.id.alarm_label); tv2.settext(values[position]); homecoming rowview; } }
listactivity
code-
public class alarmlist extends listactivity { public void oncreate(bundle icicle) { super.oncreate(icicle); requestwindowfeature(window.feature_no_title); getwindow().addflags(windowmanager.layoutparams.flag_fullscreen); string[] values = new string[] { "android", "iphone", "windowsmobile", "blackberry", "webos", "ubuntu", "windows7", "max os x", "linux", "os/2" }; // utilize custom layout alarmlistcustomadapter adapter = new alarmlistcustomadapter(this, values, "fonts/lato-light.ttf"); setlistadapter(adapter); } @override protected void onlistitemclick(listview l, view v, int position, long id) { string item = (string) getlistadapter().getitem(position); toast.maketext(this, item + " selected", toast.length_long).show(); } }
i'm not getting warnings or error in logcat. can going wrong?
i'm trying larn custom adapter implementation through here.
change this
super(context, r.layout.alarmlist_layout);
to
super(context, r.layout.alarmlist_layout,values);
since have r.layout.alarmlist_layout
there no need inflate layout 1 time again in getview
. read blackbelt's comment below.
android android-listview android-adapter
No comments:
Post a Comment