How to change the state of a CheckBox from an EditText that are in a RecyclerView? -
i have recyclerview follows:
private class productadapter extends recyclerview.adapter<productholder> { private list<product> listproductsrecyclerview; public productadapter(list<product> products){ products = product.getlistproduct(true); listproductsrecyclerview = products; amount = new string[products.size()]; } @override public productholder oncreateviewholder(viewgroup parent, int viewtype) { layoutinflater layoutinflater = layoutinflater.from(m_actorder); view view = layoutinflater.inflate(r.layout.act_item_product_adapter,parent,false); return new productholder(view, new mamountedittextlistener()); } @override public void onbindviewholder(final productholder holder, final int position) { final product product =listproductsrecyclerview.get(position); holder.medittextlistener.updateposition(holder.getadapterposition()); holder.bindproduct(product); } @override public int getitemcount() { return listproductsrecyclerview.size(); } public void setproducts(list<product> products) {listproductsrecyclerview = products;} public list<product> getproducts(){return listproductsrecyclerview;} }
private class productholder extends recyclerview.viewholder{ public mamountedittextlistener medittextlistener; private textview m_product_name; private textview m_product_cost; private textview m_product_stock; private edittext m_product_amount; private imageview m_product_photo; private checkbox m_product_ok; private product mproduct; public productholder(view itemview, mamountedittextlistener medittextlistener) { super(itemview); m_product_name = (textview) itemview.findviewbyid(r.id.adapter_product_nameproduct); m_product_cost = (textview) itemview.findviewbyid(r.id.adapter_product_amount); m_product_stock = (textview) itemview.findviewbyid(r.id.adapter_product_stock); m_product_amount = (edittext)itemview.findviewbyid(r.id.adapter_product_amount); this.medittextlistener = medittextlistener; m_product_amount.addtextchangedlistener(medittextlistener); m_product_photo = (imageview) itemview.findviewbyid(r.id.adapter_product_photo); m_product_ok = (checkbox) itemview.findviewbyid(r.id.adapter_product_ok); } public void bindproduct(product product) { mproduct = product; m_product_name.settext(mproduct.getnameproduct()); m_product_cost.settext(" costo: " + string.format("%.2f",mproduct.getcost())); m_product_stock.settext(" stock: " + integer.tostring(mproduct.getstock())); if(mproduct.getimagenproduct() != null){ byte[] decodedstring = base64.decode(mproduct.getimagenproduct(), base64.default); m_produc_photo.setimagebitmap(bitmapfactory.decodebytearray(decodedstring, 0, decodedstring.length)); } } }
public class mamountedittextlistener implements textwatcher { //here necessary analyze text entered in m_product_amount = (edittext)itemview.findviewbyid(r.id.adapter_product_amount); }
what want enable (.setchecked (true)) checkbox when m_product_amount(edittext) has value or disable (.setchecked (false)) when editext empty.
i imagine should done within public class mamountedittextlistener, have no idea how it.
i had idea this:
if (holder.m_product_amount.gettext().length()> 0){ holder.m_product_ok.setchecked(true); }
any ideas or suggestions welcome.
thanks
Comments
Post a Comment