android - ListView Inside CardView not Showing its full length -
hellow i've implemented listview inside cardview problem got is, cardview not expanding on adding list item. can me,how slove issue? have gone through different posts on stackoverflow cannot find solution :( code below
//this listview adapter class
public class employmenthistoryadapter extends baseadapter { public arraylist<employmenthistory> memploymenthistories; private context context; public employmenthistoryadapter(arraylist<employmenthistory> memploymenthistories, context context) { this.memploymenthistories = memploymenthistories; this.context = context; } @override public int getcount() { return memploymenthistories.size(); } @override public object getitem(int position) { return position; } @override public long getitemid(int position) { return 0; } @override public view getview(int position, view convertview, viewgroup parent) { view v = null; employmenthistory emphistory = memploymenthistories.get(position); if (convertview == null) { layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service); v = inflater.inflate(r.layout.list_employee_history_row, parent, false); } else { v = convertview; } textview hospital = (textview) v.findviewbyid(r.id.hospital); textview department = (textview) v.findviewbyid(r.id.department); textview startdate = (textview) v.findviewbyid(r.id.startdate); textview enddate = (textview) v.findviewbyid(r.id.enddate); textview hospitalname = (textview) v.findviewbyid(r.id.hospitalname); hospitalname.settext(emphistory.gethospital()); textview departmentname = (textview) v.findviewbyid(r.id.departmentname); departmentname.settext(emphistory.getdepartment()); textview startdate1 = (textview) v.findviewbyid(r.id.startdate1); startdate1.settext(emphistory.getstartdate()); textview enddate1 = (textview) v.findviewbyid(r.id.enddate1); enddate1.settext(emphistory.getenddate()); hospital.setvisibility(view.visible); department.setvisibility(view.visible); startdate.setvisibility(view.visible); enddate.setvisibility(view.visible); return v; }
}
//this populated listview
private void populateemploymenthistorylist() { listemployeehistory = (listview) findviewbyid(r.id.listemployeehistory); emphistory = dbhelper.getallemploymenthistory(); employmenthistoryadapter = new employmenthistoryadapter(emphistory,this); listemployeehistory.setadapter(employmenthistoryadapter); }
//this layout file added listview , have custom design list_row
<android.support.v7.widget.cardview android:id="@+id/employmenthistorycard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="@dimen/card_margin" android:layout_marginleft="@dimen/card_margin" android:layout_marginright="@dimen/card_margin"> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/employmenthistory" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerhorizontal="true" android:background="#e0e0e0" android:gravity="center" android:text="employment history" android:textappearance="@style/textappearance.appcompat.title" android:textcolor="#4a148c" /> <textview android:id="@+id/addemployment" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/employmenthistory" android:layout_margintop="15dp" android:background="?attr/selectableitembackground" android:clickable="true" android:drawableleft="@drawable/ic_add" android:drawablepadding="20dp" android:drawablestart="@drawable/ic_add" android:paddingleft="30dp" android:text="add employment" android:textcolor="#0e89d0" /> <listview android:id="@+id/listemployeehistory" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/addemployment"> </listview> </relativelayout> </android.support.v7.widget.cardview>
you need specify height listview in xml code. wrap_content not expand listview when data inflated it. specify height 200dp or something.
Comments
Post a Comment