Android - Unexpected Behavior of Keypad - EditText in ListView -


i stuck problem since last 2 days i.e. have created listview custom view variant sublayout like:

product view

problems:

  • when click on edittext of qty, displaying soft input keyboard numeric keypad , focus lost from
    edittext change of alphabetic keypad. (first screenshot below)

enter image description here

  • on second time focus of edittext works fine , taking numeric values while scrolling change keypad numeric alphabetic. (second screenshot below)

enter image description here

actually can understand problem changing on showing/hiding keyboard , because of view updating every time can keep focusing on edittext or prevent refresh views on show/hide keyboard.

my adapter code is:

class mygridviewadapter extends baseadapter {      private arraylist<productitems> productitemlist;     private layoutinflater inflater = null;      viewholder holder;      double productqtyvalue;     double productratevalue;     double productdiscountvalue;     double productofferdiscvalue;     double productdiscountedratevalue;      double amount;      public mygridviewadapter(arraylist<productitems> productitemslist) {         // todo auto-generated constructor stub         this.productitemlist = productitemslist;         inflater = (layoutinflater) getsystemservice(context.layout_inflater_service);     }      @override     public int getcount() {         // todo auto-generated method stub         return productitemlist.size();     }      @override     public object getitem(int position) {         // todo auto-generated method stub         return productitemlist.get(position);     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }      @override     public view getview(final int position, view convertview, viewgroup parent) {         // todo auto-generated method stub          if (convertview == null) {              if(isviewwithcatalog)                 convertview = inflater.inflate(r.layout.list_product_view_catalog, null);             else                 convertview = inflater.inflate(r.layout.list_product_view, null);              holder = new viewholder();              holder.prodisnewview    = (imageview) convertview.findviewbyid(r.id.productisnewimageview);             holder.prodimageview    = (imageview) convertview.findviewbyid(r.id.productimage);             holder.prodnameview     = (textview) convertview.findviewbyid(r.id.productnametextview);             holder.prodstockview    = (textview) convertview.findviewbyid(r.id.productstocktextview);             holder.prodqtyview      = (edittext) convertview.findviewbyid(r.id.productquantityvalue);              holder.prodrateview     = (textview) convertview.findviewbyid(r.id.productratevalue);             holder.proddiscview     = (textview) convertview.findviewbyid(r.id.productdiscountvalue);             holder.prodofferdiscview= (textview) convertview.findviewbyid(r.id.productofferdiscounttextviewvalue);              holder.prodoriginalrateview = (textview) convertview.findviewbyid(r.id.productoriginalratevalue);             holder.prodpackingqtyview = (textview) convertview.findviewbyid(r.id.productbundleqtyview);              //textview amount             holder.prodamountview   = (textview) convertview.findviewbyid(r.id.productamountvalue);             holder.prodpricetagview = (textview) convertview.findviewbyid(r.id.productpricetagtitle);             holder.layoutdiscountview = (linearlayout) convertview.findviewbyid(r.id.productviewmiddle);              holder.pricelayoutview1 = (linearlayout) convertview.findviewbyid(r.id.productedittextviewabove);             holder.pricelayoutview2 = (linearlayout) convertview.findviewbyid(r.id.productviewmiddle);              holder.prodqtyview.addtextchangedlistener(new generaltextwatcher(holder));              convertview.settag(holder);          } else {             holder = (viewholder) convertview.gettag();         }          final productitems currentproductitem = productitemlist.get(position);          holder.prodid           = currentproductitem.getprodid();         holder.prodimagepath    = currentproductitem.getprodimagepath();         holder.proddesc         = currentproductitem.getproddesc();         holder.prodstock        = currentproductitem.getprodstock();         holder.prodlowstock     = currentproductitem.getprodlowstock();         holder.prodstockdate    = currentproductitem.getprodstockdate();         holder.prodpackingqty   = currentproductitem.getprodpackingqty();         holder.prodisnew        = currentproductitem.getprodisnew();         holder.prodrate         = currentproductitem.getprodrate();         holder.proddisc         = currentproductitem.getproddisc();         holder.prodofferdisc    = currentproductitem.getprodofferdisc();          holder.prodisnewview.setvisibility(holder.prodisnew == 1 ? view.visible : view.gone);            string medium_path = holder.prodimagepath.isempty() ? "" : holder.prodimagepath.replace("product_image/", "product_image/medium/");         aq.id(holder.prodimageview).image(medium_path, true, true, 0, r.drawable.no_image, bitmapfactory.decoderesource(getresources(), r.drawable.no_image), aquery.fade_in);          holder.prodimageview.settag(holder);         holder.prodimageview.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 // todo auto-generated method stub                 intent intent = new intent(selectproductactivity.this, fullscreenimagepreviewactivity.class);                 intent.addflags(intent.flag_activity_new_task);                 intent.putextra("position", position);                 intent.putextra("items", productitemlist);                 startactivity(intent);             }         });          /**          * chech whether stock less low_stock          */         if(holder.prodstock <= holder.prodlowstock && isparentnull)         {             /** product stock changing 'k' format if greater 10000 */             if(holder.prodlowstock > 999999)                 holder.prodstockview.settext(string.valueof(holder.prodstock).substring(0,3)+"k+");             else if(holder.prodstock > 99999)                 holder.prodstockview.settext(string.valueof(holder.prodstock).substring(0,2)+"k+");             else                 holder.prodstockview.settext(""+holder.prodstock);              /**              * changing bgcolor               * if stock less 0 => red background               * else => green background              */             holder.prodstockview.setbackgroundresource(holder.prodlowstock <= 0 ? r.drawable.round_corner_red : r.drawable.round_corner_green);             holder.prodstockview.setvisibility(view.visible);         } else {             holder.prodstockview.setvisibility(view.gone);         }          string code = currentproductitem.getprodcode();         code = (code.isempty() || code.equals("null")) ? "" : "["+code+"] ";         holder.prodnameview.settext(code + "" +currentproductitem.getprodname());          log.w(tag, "packing qty : "+ holder.prodpackingqty);         if(holder.prodpackingqty > 0) { //&& isparentnull) {             holder.prodpackingqtyview.settext("packing qty: "+holder.prodpackingqty);             holder.prodpackingqtyview.setvisibility(view.visible);         }         else              holder.prodpackingqtyview.setvisibility(view.invisible);          holder.prodqtyview.setonfocuschangelistener(new onfocuschangelistener() {              @override             public void onfocuschange(view v, boolean hasfocus) {                 // todo auto-generated method stub                 if (!hasfocus) {                     viewholder viewholder = (viewholder) v.gettag();                     savedata(viewholder);                 }             }         });          holder.prodqtyview.settag(holder);         holder.prodrateview.settag(holder);         holder.proddiscview.settag(holder);         holder.prodofferdiscview.settag(holder);          productqtyvalue = 0.0;         productratevalue = currentproductitem.getprodrate();         productdiscountvalue = currentproductitem.getproddisc();         productofferdiscvalue = currentproductitem.getprodofferdisc();          holder.prodrateview.settext(""+new bigdecimal((productratevalue - (productratevalue * (productdiscountvalue + productofferdiscvalue) / 100))).setscale(2, roundingmode.down));          /** first check whether value of saved product array > 0 or not..*/         productitems savedprodtemp = proditemssavedlist.get(holder.prodid, null);          if(savedprodtemp != null)         {             productqtyvalue = savedprodtemp.getprodqty();             holder.prodqtyview.settext(""+productqtyvalue);         } else {             holder.prodqtyview.settext("");         }          amount = (productqtyvalue * productratevalue) - ((productqtyvalue * productratevalue) * ((productdiscountvalue + productofferdiscvalue) / 100));          if(productqtyvalue > holder.prodstock && isparentnull) {             holder.prodqtyview.settextcolor(color.red);             holder.prodqtyview.setbackgroundresource(r.drawable.edittextred_edit_text_holo_light);         }         else {             holder.prodqtyview.settextcolor(color.black);             holder.prodqtyview.setbackgroundresource(r.drawable.myactionbar_edit_text_holo_dark);         }          holder.prodamountview.settext("rs." + new bigdecimal(amount).setscale(2, roundingmode.ceiling));          return convertview;     }      public class viewholder {         int prodid;         string prodimagepath;         string proddesc;         double prodrate;         double proddisc;         double prodofferdisc;         double prodstock;         double prodlowstock;         string prodstockdate;         double prodpackingqty;         int prodisnew;          imageview prodisnewview;         imageview prodimageview;         textview prodnameview;         textview prodstockview;         edittext prodqtyview;         textview prodrateview;         textview proddiscview;         textview prodofferdiscview;          textview prodoriginalrateview;         textview prodamountview;         textview prodpackingqtyview;         textview prodpricetagview;          linearlayout layoutdiscountview;          linearlayout pricelayoutview1;         linearlayout pricelayoutview2;           } } 

activity layout of product select_product.xml:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:id="@+id/productparentview"     android:layout_width="fill_parent"     android:layout_height="match_parent" >      <spinner         android:id="@+id/categoryspinner"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_marginleft="5dp"         android:layout_marginright="5dp"         android:prompt="@string/prompt_select_category" />      <listview         android:id="@+id/productlist"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:layout_below="@+id/categoryspinner"         android:layout_margin="5dp"         android:descendantfocusability="afterdescendants"          android:focusable="false"         android:layout_marginbottom="10dp"         android:fastscrollenabled="true" >     </listview>      <textview         android:id="@+id/productifnoavailable"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerhorizontal="true"         android:layout_centervertical="true"         android:gravity="center"         android:text="@string/error_no_products_available_for_this_category"         android:textappearance="?android:attr/textappearancelarge"         android:textcolor="@android:color/holo_red_dark"         android:visibility="gone" />  </relativelayout> 

heading row xml used in getview() list_product_variant_heading_view.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/productvariantheadingrelativelayout"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_margin="5dp"     android:background="@drawable/bg_white_shadow"     android:gravity="center_horizontal"     android:padding="3dp" >      <relativelayout         android:id="@+id/layoutproductnamestock"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_alignparenttop="true"         android:gravity="center_horizontal"         android:orientation="horizontal" >          <relativelayout             android:id="@+id/productnamelayoutinnerforclick"             android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:layout_marginleft="5dp"             android:layout_marginright="5dp"             android:layout_toleftof="@+id/productisnewimageview"             android:orientation="horizontal" >              <textview                 android:id="@+id/productnametextview"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="@string/product_name"                 android:textcolor="@android:color/black"                 android:textsize="@dimen/product_name_text_size" />         </relativelayout>          <imageview             android:id="@+id/productisnewimageview"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentright="true"             android:layout_marginleft="5dp"             android:contentdescription="@string/app_name"             android:src="@drawable/new_icon" />     </relativelayout>      <linearlayout         android:id="@+id/productrowviewlinearlayout"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_below="@+id/layoutproductnamestock"         android:orientation="vertical" >     </linearlayout>  </relativelayout> 

sublayouts of product row creating following files.

list_product_variant_single_row_view.xml

list_product_variant_multiple_row_view.xml

noticed: view refreshing , losing focus edittext when keypad open. that's why keypad changing view numeric alphabetic. have changed androidmanifest.xml android:windowsoftinputmode="statealwayshidden" , android:configchanges="keyboardhidden|orientation" not working me.

your appreciated.

this due listview recycle mechanism. issue raised in google android groups. better place quantity items @ check out or change edittext drop downs giving numbers in dropdowns.

issues focusing edittexts in listview (android)

https://code.google.com/p/android/issues/detail?id=31165

edit working option:

android:windowsoftinputmode="statealwayshidden|adjustpan" 

Comments