android - First EditText in a ListView automatically requests focus -
my listview
contains 4 edittext
.
every time user types in or clicks textview
(not first 1 in list):
the first
textview
gets focusthe clicked
textview
ortextview
in user typed in gets focus
sometimes cycle repeated 2 or 3 times.
this stacktrace of onfocuschange
method:
at it.softecspa.workflowmanager.views.integernumber_type.onfocuschange(integernumber_type.java:308) @ android.view.view.onfocuschanged(view.java:5592) @ android.widget.textview.onfocuschanged(textview.java:8855) @ android.widget.edittext.onfocuschanged(edittext.java:182) @ android.view.view.clearfocusinternal(view.java:5475) @ android.view.view.unfocus(view.java:5508) @ android.view.viewgroup.unfocus(viewgroup.java:982) @ android.view.viewgroup.unfocus(viewgroup.java:982) @ android.view.viewgroup.requestchildfocus(viewgroup.java:672) @ android.view.viewgroup.requestchildfocus(viewgroup.java:678) @ android.view.viewgroup.requestchildfocus(viewgroup.java:678) @ android.view.view.handlefocusgaininternal(view.java:5340) @ android.view.view.requestfocusnosearch(view.java:8080) @ android.view.view.requestfocus(view.java:8059) @ android.view.view.requestfocus(view.java:8026) @ android.view.view.requestfocus(view.java:8005) @ android.widget.listview.layoutchildren(listview.java:1766) @ android.widget.abslistview.onlayout(abslistview.java:2632) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.relativelayout.onlayout(relativelayout.java:1077) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.linearlayout.setchildframe(linearlayout.java:2102) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1956) @ android.widget.linearlayout.onlayout(linearlayout.java:1865) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.linearlayout.setchildframe(linearlayout.java:2102) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1956) @ android.widget.linearlayout.onlayout(linearlayout.java:1865) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.framelayout.layoutchildren(framelayout.java:573) @ android.widget.framelayout.onlayout(framelayout.java:508) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.linearlayout.setchildframe(linearlayout.java:2102) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1956) @ android.widget.linearlayout.onlayout(linearlayout.java:1865) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.widget.framelayout.layoutchildren(framelayout.java:573) @ android.widget.framelayout.onlayout(framelayout.java:508) @ android.view.view.layout(view.java:16550) @ android.view.viewgroup.layout(viewgroup.java:5303) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2308) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:2021) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1180) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:6558) @ android.view.choreographer$callbackrecord.run(choreographer.java:777) @ android.view.choreographer.docallbacks(choreographer.java:590) @ android.view.choreographer.doframe(choreographer.java:560) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:763) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:145) @ android.app.activitythread.main(activitythread.java:5832) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1399) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1194)
i think need see more of code (xml , code launch listview). equally, had problems maintaining focus in views. here 1 example works fine , doesn't use onfocuschange()
public class mainactivity extends appcompatactivity { myadapter.viewholder holder; myadapter adapt; list<string> dataarray; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); populatelist(); } private void populatelist() { dataarray = new arraylist<string>(); listview listview = (listview) findviewbyid(android.r.id.list); dataarray.add("item 1"); dataarray.add("item 2"); dataarray.add("item 3"); dataarray.add("item 4"); adapt = new myadapter(this, r.layout.list_rows, dataarray); listview.setadapter(adapt); } private class myadapter extends arrayadapter<string> { context context; list<string> itemlist = new arraylist<string>(); int layoutresourceid; public myadapter(context context, int layoutresourceid, list<string> objects) { super(context, layoutresourceid, objects); this.layoutresourceid = layoutresourceid; this.itemlist = objects; this.context = context; } @override public view getview(final int position, view convertview, final viewgroup parent) { layoutinflater inflater = (layoutinflater) context .getsystemservice(context.layout_inflater_service); holder = null; if (convertview == null) { //inflate layout convertview = inflater.inflate(r.layout.list_rows, parent, false); //create view holder holder = new viewholder(); //find views holder.et1 = (edittext) convertview.findviewbyid(r.id.et_1); holder.et2 = (edittext) convertview.findviewbyid(r.id.et_2); holder.et3 = (edittext) convertview.findviewbyid(r.id.et_3); holder.et4 = (edittext) convertview.findviewbyid(r.id.et_4); //attach views holder convertview.settag(holder); } else { //return views if converter not null holder = (viewholder) convertview.gettag(); } return convertview; } class viewholder { edittext et1; edittext et2; edittext et3; edittext et4; } }
and if need maintain focus in 1 edittext
in particular holder.et1.requestfocus();
i hope helps, if not i'll wait code (;
Comments
Post a Comment