java - add views programmatically on DialogFragment leaves empty space -
given have custom dialog class extends dialogfragment
. suppose have dialog shows doctor information in it, has booking schedules consist of string arraylist shows available date.
in layout have prepared placeholder image, name, , have prepared vertical linear layout addviews programmatically of arraylist java class.
i looping list addview linearlayout
private doctor doctor; // has doctor.schedule = arraylist<string> @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { layoutsearchdoctordialogbinding binding = databindingutil.inflate(inflater, r.layout.layout_search_doctor_dialog, container, true); getdialog().getwindow().requestfeature(window.feature_no_title); binding.layoutschedule.removeallviewsinlayout(); (schedule schedule : doctor.schedule) { view view = inflater.inflate(r.layout.item_schedule, null); textview textdays = (textview) view.findviewbyid(r.id.text_days); textview texthours = (textview) view.findviewbyid(r.id.text_hours); textdays.settext(schedule.day); texthours.settext(schedule.hours); binding.layoutschedule.addview(view, new viewgroup.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent)); } binding.setviewmodel(new searchdoctordialogviewmodel(doctor)); binding.btncall.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { ((searchdoctorview) getactivity()).checkrecords(doctor.phonenumber); dismiss(); } }); return binding.getroot(); }
here dialog layout r.layout.layout_search_doctor_dialog
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="@dimen/dimen_16dp"> <com.bloonerd.rspondokindah.custom.circleimageview android:layout_width="@dimen/dimen_60dp" android:layout_height="@dimen/dimen_60dp" android:layout_margintop="@dimen/dimen_20dp" android:layout_marginbottom="@dimen/dimen_20dp" android:layout_gravity="center" app:imageurl="@{viewmodel.image}"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" tools:text="michael jackson" android:text="@{viewmodel.doctorname}" android:textstyle="bold" android:textcolor="@color/black" android:ellipsize="end" android:textsize="@dimen/dimen_16sp"/> <!-- linear layout below addviews --> <linearlayout android:id="@+id/layout_schedule" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingleft="@dimen/dimen_16dp" android:paddingright="@dimen/dimen_16dp"/> </linearlayout>
also adding linearlayout addview r.layout.item_schedule
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <textview android:id="@+id/text_days" style="@style/width0heightwrapstyle" android:textsize="@dimen/dimen_16sp" android:textcolor="@color/text_small"/> <textview android:id="@+id/text_hours" style="@style/wrapcontentstyle" android:textsize="@dimen/dimen_16dp" android:textcolor="@color/text_small"/> </linearlayout>
when debug it, shows looping doctor.schedule , adding view. shows first index of string arraylist. leaves empty spaces in linearlayout looks string arraylist added hidden.
moreover, after check uiautomatorviewer
there one child view inside layout_schedule
linearlayout
i realize specific dialogfragment, in recyclerview can show list fine
how now: ---------------------------------------------> what want
__________ __________ __________ | | -----> |[item 1]| -----> |[item 1]| ---------- loop | | |[item 2]| | | |[item 3]| | | |[item 4]| | | |[item 5]| ---------- ----------
Comments
Post a Comment