android - Recycle-view item components overlapping -
in second item seems overlapping elements.it can due longer length text not fix it. fragment_meds.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="175dp" android:orientation="horizontal"> <linearlayout android:layout_width="0dp" android:layout_weight="0.35" android:layout_height="match_parent" android:padding="10dp" android:orientation="vertical"> <imageview android:background="@drawable/default_meds_small" android:layout_width="100dp" android:layout_height="100dp" /> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.65" android:paddingtop="10dp" android:orientation="vertical"> <textview android:id="@+id/id" android:layout_gravity="left" android:textstyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/black" /> <textview android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/black" /> <textview android:drawableleft="@drawable/resupply" android:id="@+id/resupply_button" android:drawablepadding="5dp" android:textcolor="@color/black" android:text="@string/add_to_resupply" android:layout_width="wrap_content" android:layout_gravity="right" android:layout_margintop="40dp" android:layout_height="20dp" /> </linearlayout> </linearlayout>
allmedicinerecyclerviewadapter.java
public class allmedicinerecyclerviewadapter extends recyclerview.adapter<allmedicinerecyclerviewadapter.viewholder> { private final list<medicinelist> mvalues; private final allmedicinefragment.onlistfragmentinteractionlistener mlistener; context context; dbhelper db; private list<com.allion.medimap.dto.medicine> mmedicinedata = new arraylist<com.allion.medimap.dto.medicine>(); public allmedicinerecyclerviewadapter(list<medicinelist> items, allmedicinefragment.onlistfragmentinteractionlistener listener, context context) { mvalues = items; mlistener = listener; this.context = context; } @override public viewholder oncreateviewholder(viewgroup parent, int viewtype) { view view = layoutinflater.from(parent.getcontext()) .inflate(r.layout.fragment_meds, parent, false); db = new dbhelper(context); return new viewholder(view); } @override public void onbindviewholder(final viewholder holder, final int position) { holder.mitem = mvalues.get(position); holder.midview.settext(mvalues.get(position).getmedicine().getname()); holder.resupply_button.settext(r.string.add_to_resupply); mmedicinedata = db.getallmedicine(); log.e("adpater", "start"); log.e("size", string.valueof(mmedicinedata.size())); if (mvalues.get(position).getmedicine().getmed_id().equals("pack_med")) { if (sessionmanager.getinstance(context).getpack()) { log.e("test_add_pack", "add"); holder.resupply_button.settext(r.string.added_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.check, 0, 0, 0); } else { log.e("test_add_pack", "added"); holder.resupply_button.settext(r.string.add_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.resupply, 0, 0, 0); } } else { (int = 0; < mmedicinedata.size(); i++) { if(mvalues.get(position).getmedicine().getcategory().equals("prn")) { holder.resupply_button.setvisibility(view.gone); } else { if (mvalues.get(position).getmedicine().getname().equals(mmedicinedata.get(i).getname())) { log.e("true_name1", mmedicinedata.get(i).getid()); log.e("true_name2", mvalues.get(position).getmedicine().getmed_id()); holder.resupply_button.settext(r.string.added_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.check, 0, 0, 0); } } } } holder.mview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (null != mlistener) { if (!mvalues.get(position).getmedicine().getmed_id().equals("pack_med")) { startmedicinedetailfromtimelineactivity(context, mvalues.get(position).getmedicine()); mlistener.onlistfragmentinteraction(holder.mitem); } } } }); holder.resupply_button.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { if (mvalues.get(position).getmedicine().getmed_id().equals("pack_med")) { if (sessionmanager.getinstance(context).getpack()) { log.e("test_add_pack", "add"); sessionmanager.getinstance(context) .setpack(context, false); holder.resupply_button.settext(r.string.add_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.resupply, 0, 0, 0); } else { log.e("test_added_pack", "added"); sessionmanager.getinstance(context) .setpack(context, true); holder.resupply_button.settext(r.string.added_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.check, 0, 0, 0); } } else { if (holder.resupply_button.gettext().tostring().equals("add resupply")) { log.e("test_added", "added"); com.allion.medimap.dto.medicine medicine = new com.allion.medimap.dto.medicine(mvalues.get(position).getmedicine().getmed_id(), mvalues.get(position).getmedicine().getname(), mvalues.get(position).getmedicine().getcategory()); db.insertmedicinedetail(medicine); holder.resupply_button.settext(r.string.added_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.check, 0, 0, 0); } else { // db.deleterow(mvalues.get(position).getmedicine().getmed_id()); holder.resupply_button.settext(r.string.add_to_resupply); holder.resupply_button.setcompounddrawableswithintrinsicbounds(r.drawable.resupply, 0, 0, 0); log.e("test_add", "added"); // } } } }); } @override public int getitemcount() { return mvalues.size(); } @override public int getitemviewtype(int position) { return position; } public class viewholder extends recyclerview.viewholder { public final view mview; public final textview midview; public final textview mcontentview; public final textview resupply_button; public medicinelist mitem; public viewholder(view view) { super(view); mview = view; midview = (textview) view.findviewbyid(r.id.id); mcontentview = (textview) view.findviewbyid(r.id.content); resupply_button = (textview) view.findviewbyid(r.id.resupply_button); } @override public string tostring() { return super.tostring() + " '" + mcontentview.gettext() + "'"; } } }
above added related codes , here need mention i disable item reusability function of recycle-view.i grateful if 1 can me fix issue.
try this
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="175dp" android:orientation="horizontal"> <imageview android:id="@+id/iv" android:layout_width="100dp" android:layout_height="100dp" android:padding="10dp" android:src="@drawable/default_meds_small"/> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_torightof="@+id/iv" android:paddingtop="10dp" android:orientation="vertical"> <textview android:id="@+id/id" android:layout_gravity="left" android:textstyle="bold" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/black" /> <textview android:id="@+id/content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textcolor="@color/black" /> <textview android:drawableleft="@drawable/resupply" android:id="@+id/resupply_button" android:drawablepadding="5dp" android:textcolor="@color/black" android:text="@string/add_to_resupply" android:layout_width="wrap_content" android:layout_gravity="right" android:layout_margintop="40dp" android:layout_height="20dp" /> </linearlayout> </relativelayout>
Comments
Post a Comment