Android Listview item Partially Visible -
i created custom listview adapter viewholder , used listfragment, reason dont know, last listview item not render totally
adapter code
public class listviewadapter extends arrayadapter<listitem> { public listviewadapter(context context, list<listitem> items) { super(context, r.layout.row, items); } @override public view getview(int position, view convertview, viewgroup parent) { viewholder viewholder; if(convertview == null) { layoutinflater inflater = layoutinflater.from(getcontext()); viewholder = new viewholder(); viewholder.ivicon = (imageview) convertview.findviewbyid(r.id.ivicon); viewholder.tvtitle = (textview) convertview.findviewbyid(r.id.tvtitle); viewholder.tvdescription = (textview) convertview.findviewbyid(r.id.tvdescription); convertview.settag(viewholder); } else { // recycle inflated view viewholder = (viewholder) convertview.gettag(); } // update item view listitem item = getitem(position); if(item!=null){ viewholder.ivicon.setimagedrawable(item.icon); viewholder.tvtitle.settext(item.title); viewholder.tvdescription.settext(item.description); } return convertview; } /** * view holder design pattern prevents using findviewbyid() * repeatedly in getview() method of adapter. * * @see http://developer.android.com/training/improving-layouts/smooth-scrolling.html#viewholder */ private static class viewholder { imageview ivicon; textview tvtitle; textview tvdescription; } }
layout
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:gravity="center_vertical" android:background="@color/frame_background" android:padding="5dp" > <!-- innner view - provides white rectangle --> <relativelayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/frame" > <!-- icon view --> <imageview android:id="@+id/ivicon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="5dp" android:contentdescription="desc" android:scaletype="fitxy" android:layout_alignparentleft="true" android:src="@mipmap/ic_launcher" /> <!-- container view title , description --> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@id/ivicon" android:layout_centervertical="true" > <!-- title view --> <textview android:id="@+id/tvtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="@android:style/textappearance.medium" /> <!-- description view --> <textview android:id="@+id/tvdescription" android:layout_below="@id/tvtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textappearance="@android:style/textappearance.small" android:padding="3dp" /> </relativelayout> </relativelayout>
and fragment code since using listfragment
public class introfragment extends listfragment { private list<listitem> mitems; // listview items list @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); // initialize items list mitems = new arraylist<listitem>(); resources resources = getresources(); string[] factfiles=resources.getstringarray(r.array.sunfacts); mitems.add(new listitem(resources.getdrawable(r.mipmap.ic_launcher), factfiles[i], factfiles[i])); } // initialize , set list adapter setlistadapter(new listviewadapter(getactivity(), mitems)); } @override public void onviewcreated(view view, bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); // remove dividers listview of listfragment getlistview().setdivider(null); } @override public void onlistitemclick(listview l, view v, int position, long id) { // retrieve thelistview item listitem item = mitems.get(position); // toast.maketext(getactivity(), item.title, toast.length_short).show(); } }
the screenshot below shows mean,notice white edge of new listview item @ bottom, , listview not scroll anymore. screenshot (cant upload here due rep points)
thanks in advance..this driving me half bean , bananas..
Comments
Post a Comment