java - Focus to the EditText doesn't work -
i'm using broadcast receiver show dialog.so flow of code like:
step1 getting requestcode value
step2 based on requestcode broadcast receiver goes if or else if or else part
step3 if value entered using scanner edittext(i.e scan) doesn't matches shows toast "item not available".
step 4 once "item not available" toast comes need focus on edittext(i.e scan) next time can put fresh value in after clearing it.
so question "how can give focus edittext" , set edittext(i.e scan).
for reference i'm attaching snap code snippet , layout.xml.please have , drop suggestions why focus going listview.
.java snippet
final broadcastreceiver mbroadcastreceiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { if (intent != null) { loc = mspinner.getitematposition(mspinner.getselecteditemposition()) .tostring(); final string itemno; final string desc; final string stockunit; final string pickseq; final string qtycount; final string qtyonhand; final button mok; final button mcancel; final button mplus; final button mminus; final edittext medtqtycount; final edittext medtitem; final edittext medtdesc; final edittext medtuom; final databasehandler dbhandler; final string[] uom = null; int requestcode; layoutinflater li = layoutinflater.from(inventorycount.this); view promptsview = li.inflate(r.layout.quantityupdate, null); alertdialog.builder alertdialogbuilder = new alertdialog.builder( inventorycount.this); alertdialogbuilder.setview(promptsview); //requestcode=integer.parseint(intent.getstringextra("idx")); requestcode=intent.getintextra("idx", -1); // create alert dialog final alertdialog alertdialog = alertdialogbuilder.create(); dbhandler = new databasehandler(inventorycount.this); medtuom = (edittext) promptsview.findviewbyid(r.id.edt_mseshipuom_mic); mok = (button) promptsview.findviewbyid(r.id.btn_mseshipok_mic); mcancel = (button) promptsview.findviewbyid(r.id.btn_mseshipcancel_mic); mplus = (button) promptsview.findviewbyid(r.id.btn_mseshipincr_mic); mminus = (button) promptsview.findviewbyid(r.id.btn_mseshipdecr_mic); medtqtycount = (edittext) promptsview .findviewbyid(r.id.edt_shipshiped_mic); medtdesc = (edittext) promptsview .findviewbyid(r.id.edt_mseshipqtyord_mic); medtitem = (edittext) promptsview .findviewbyid(r.id.edt_mseshipitemno_mic); if (requestcode == 1) { } else if (requestcode == 0) { // itemno /*if (resultcode == result_ok) { log.i("scan resul format: ", intent.getstringextra("scan_result_format")); */ string itno = intent.getstringextra("scan_result"); dbhelper.getreadabledatabase(); mic_inventory mic_inventory = dbhelper.getmicinventorydetails( loc, itno); dbhelper.closedatabase(); if (mic_inventory != null) { loc = mspinner.getitematposition( mspinner.getselecteditemposition()).tostring(); itemno = mic_inventory.getitemno(); desc = mic_inventory.getitemdescription(); pickseq = mic_inventory.getpickingseq(); stockunit = mic_inventory.getstockunit(); qtyonhand = mic_inventory.getqoh();// value gives // qohand qtycount = mic_inventory.getqc(); medtitem.settext(itemno); medtdesc.settext(desc); medtqtycount.settext(qtycount); medtuom.settext(stockunit); mplus.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) { // todo auto-generated method stub string = medtqtycount.gettext().tostring(); int b = integer.parseint(a); b = b + 1; = a.valueof(b); medtqtycount.settext(a); } }); mminus.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub int c = integer.parseint(medtqtycount.gettext() .tostring()); c = c - 1; medtqtycount.settext(new integer(c).tostring()); } }); mok.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub /* * uom[mspinneruom.getselecteditemposition()] = * medtqtycount .gettext().tostring(); */ mic_uominternal mic_uom = new mic_uominternal(); mic_uom.setlocation(loc); mic_uom.setitemno(itemno); string updatedqtycount = medtqtycount.gettext() .tostring(); if (!qtycount.equals(updatedqtycount)) { mic_uom.setqc(double .parsedouble(updatedqtycount)); mic_uom.setuom(stockunit); mic_inventory mic_inventory = new mic_inventory(); mic_inventory.setitemdescription(desc); mic_inventory.setitemno(itemno); mic_inventory.setlocation(loc); mic_inventory.setpickingseq(pickseq); mic_inventory.setqc(updatedqtycount); mic_inventory.setqoh(qtyonhand); mic_inventory.setstockunit(stockunit); dbhandler.getwritabledatabase(); string result = dbhandler .insertintointernal(mic_uom); if (result.equals("success")) { result = dbhandler.updatemic(mic_inventory); } dbhandler.closedatabase(); } intent = new intent(inventorycount.this, inventorycount.class); i.putextra("et", 1); i.putextra("location", loc); // i.putextra("id", id); startactivity(i); // inventorycount.this.finish(); } }); mcancel.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub alertdialog.cancel(); } }); // show alertdialog.show(); } else { /* * toast.maketext(this, "item not available", * toast.length_long).show(); */ toasttext.settext("item not available"); toast toast = new toast(getbasecontext()); toast.setgravity(gravity.center_vertical, 0, 410); toast.setduration(toast.length_short); toast.setview(toastlayout); toast.show(); lstview.setfocusable(false); msearchtext.requestfocus(); /*inputmethodmanager imm = (inputmethodmanager) getsystemservice(context.input_method_service); imm.showsoftinput(msearchtext, inputmethodmanager.show_implicit);*/ msearchtext.settext(""); } else if (requestcode == 2) { } else { toasttext.settext("problem in scanning"); toast toast = new toast(getapplicationcontext()); toast.setgravity(gravity.center_vertical, 0, 410); toast.setduration(toast.length_short); toast.setview(toastlayout); toast.show(); } }
layout.xml
<?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="match_parent" android:background="@drawable/border_green" android:descendantfocusability="beforedescendants" android:focusableintouchmode="true" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" > <textview android:id="@+id/txt_invtitle" style="@style/pagetitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="5dp" android:text="@string/invtitle" /> <view android:id="@+id/txt_invview" android:layout_width="match_parent" android:layout_height="2dip" android:layout_below="@+id/txt_invtitle" android:layout_marginleft="10dp" android:layout_marginright="10dp" android:background="#2e9afe" /> <linearlayout android:id="@+id/invlocation" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_below="@+id/txt_invview" android:layout_margintop="16dp" > <textview android:id="@+id/txtloc" style="@style/textregular" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:gravity="left|center" android:text="@string/location" /> <spinner android:id="@+id/sploc" style="@style/spinneritemapptheme" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight=".5" android:editable="false" /> </linearlayout> <linearlayout android:id="@+id/invscantype" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/invlocation" android:layout_gravity="center" android:layout_marginbottom="3dp" android:layout_marginleft="3dp" android:layout_margintop="18dp" android:orientation="horizontal" > <edittext android:id="@+id/edt_search_mic" style="@style/edittextapptheme_scan" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="3dp" android:layout_weight=".15" android:gravity="center" android:hint="@string/scan" /> <radiogroup android:id="@+id/radioscanbasedon_mic" style="@style/radiobuttonapptheme" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <radiobutton android:id="@+id/radioinum_mic" style="@style/textregular" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight=".25" android:button="@drawable/radiobutton_selector" android:checked="true" android:drawablepadding="50dp" android:paddingleft="10dip" android:text="@string/itemno" /> <radiobutton android:id="@+id/radionum_mic" style="@style/textregular" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="5dp" android:button="@drawable/radiobutton_selector" android:checked="false" android:layout_marginright="5dp" android:layout_weight=".25" android:drawablepadding="50dp" android:paddingleft="10dip" android:text="@string/manfno" /> <radiobutton android:id="@+id/radioupc_mic" style="@style/textregular" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="5dp" android:button="@drawable/radiobutton_selector" android:checked="false" android:layout_marginright="5dp" android:layout_weight=".25" android:drawablepadding="50dp" android:paddingleft="10dip" android:text="@string/upc" /> </radiogroup> </linearlayout> <horizontalscrollview android:id="@+id/scroll_full_mic" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/invscantype" > <linearlayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_margintop="25dp" android:orientation="vertical" > <linearlayout android:id="@+id/lay_fulltitle_mic" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#000000" android:orientation="horizontal" android:padding="5dp" > <textview style="@style/textregular_list" android:layout_width="105dp" android:layout_height="wrap_content" android:text="@string/itemno" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> <textview style="@style/textregular_list" android:layout_width="130dp" android:layout_height="wrap_content" android:gravity="center|left" android:text="@string/description" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> <textview style="@style/textregular_list" android:layout_width="140dp" android:layout_height="wrap_content" android:layout_marginleft="4dp" android:gravity="center|left" android:text="@string/pick_seq" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> <textview style="@style/textregular_list" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_marginleft="4dp" android:gravity="center|left" android:text="@string/qoh" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> <textview style="@style/textregular_list" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_marginleft="4dp" android:gravity="center|left" android:text="@string/qc" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> <textview style="@style/textregular_list" android:layout_width="100dp" android:layout_height="wrap_content" android:layout_marginleft="4dp" android:gravity="center|left" android:text="@string/uom" android:textappearance="?android:attr/textappearancesmall" android:textstyle="bold" /> </linearlayout> <listview android:id="@+id/lst_msefull_mic" android:layout_width="match_parent" android:layout_height="match_parent" style="@style/listviewapptheme.white" > </listview> </linearlayout> </horizontalscrollview> <linearlayout android:id="@+id/lay_po_mic" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentleft="true" android:layout_marginbottom="41dp" android:gravity="center_horizontal" android:orientation="horizontal" android:visibility="gone" > <button android:id="@+id/btn_orderlstimport_mic" android:layout_width="100dp" android:layout_height="100dp" android:textsize="18dp" android:textstyle="bold" /> <button android:id="@+id/btn_orderlstexport_mic" android:layout_width="100dp" android:layout_height="100dp" android:textsize="18dp" android:textstyle="bold" /> <button android:id="@+id/btn_orderlstexit_mic" android:layout_width="100dp" android:layout_height="100dp" android:textsize="18dp" android:textstyle="bold" /> </linearlayout> </relativelayout>
what this:
lstview.post(new runnable() { @override public void run() { msearchtext.requestfocus(); } });
Comments
Post a Comment