android - keyboard reset radiogroup value -
android - keyboard reset radiogroup value -
i have custom listview radiogroup in each row. when alter checked radio button, phone call dialog edittext fields (using oncheckedchanged() method). but, when focused edittext write something, lose checked radiobuttons covered keyboard, , grouping returns default alternative selected. can help me?
list adapter
@override public view getview(int position, view convertview, viewgroup parent) { view row = convertview; contractitemholder cih = new contractitemholder(); if (row == null){ layoutinflater inflater = ((activity)context).getlayoutinflater(); row = inflater.inflate(r.layout.row_proposals_item, parent, false); cih.settvitemtitle((textview)row.findviewbyid(r.id.textviewitemtitle)); cih.setrgitemstatus((radiogroup)row.findviewbyid(r.id.radiogroupstatus)); row.settag(cih); }else { cih=(contractitemholder)row.gettag(); } final contractitem ci = list.get(position); cih.getrgitemstatus().setoncheckedchangelistener(new oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup group, int checkedid) { groupsel = group; int selected = group.getcheckedradiobuttonid(); dialog d; switch (selected) { case r.id.radioaccepted: d = createdialog(context, accepted_code, ci, selected); d.show(); break; case r.id.radiorefused: d = createdialog(context, refused_code, ci, selected); d.show(); break; default: break; } } }); cih.gettvitemtitle().settext(ci.getdescitem()); homecoming row; }
list item layout (the row..)
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:padding="5dp" android:gravity="center"> <textview android:id="@+id/textviewitemtitle" android:layout_width="0dp" android:layout_height="wrap_content" android:text="large text" android:layout_weight="3" android:textappearance="?android:attr/textappearancelarge"/> <radiogroup android:id="@+id/radiogroupstatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_weight="1" android:showdividers="middle"> <radiobutton android:id="@+id/radionull" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="non proposto" android:checked="true" android:textappearance="?android:attr/textappearancelarge"/> <radiobutton android:id="@+id/radiopending" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="in trattativa" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@color/blue"/> <radiobutton android:id="@+id/radioaccepted" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="accettato" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@color/green"/> <radiobutton android:id="@+id/radiorefused" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="rifiutato" android:textappearance="?android:attr/textappearancelarge" android:textcolor="@color/red"/> </radiogroup> </linearlayout>
dialog impl
private dialog createdialog(context context, final int code, contractitem item,final int selected){ //type: refused, accepted d = new dialog(context); d.settitle(item.getdescitem()); d.setcontentview(r.layout.layout_dialog_prop); d.getwindow().setlayout(900, layoutparams.wrap_content); d.getwindow().setsoftinputmode(windowmanager.layoutparams.soft_input_state_hidden); button btnok = (button)d.findviewbyid(r.id.buttonpropok); button btncancel = (button)d.findviewbyid(r.id.buttonpropcancel); btncancel.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { d.dismiss(); } }); btnok.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { d.dismiss(); } }); homecoming d; }
dialog layout
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="vertical" > <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="50dp" > <edittext android:id="@+id/edittextdiscount" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="30dp" android:ems="10" android:hint="sconto proposto" android:inputtype="number" android:textappearance="?android:attr/textappearancelarge" > <requestfocus /> </edittext> <spinner android:id="@+id/spinnerscuse" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margintop="30dp" android:textappearance="?android:attr/textappearancelarge" android:visibility="gone" /> <edittext android:id="@+id/edittext1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="30dp" android:ems="10" android:gravity="top" android:hint="note" android:inputtype="textmultiline" android:textappearance="?android:attr/textappearancelarge" /> </linearlayout> <view android:id="@+id/view2" android:layout_width="match_parent" android:layout_height="2dp" android:layout_margintop="30dp" android:background="@android:color/holo_blue_light" /> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" > <button android:id="@+id/buttonpropcancel" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:color/transparent" android:text="annulla" android:textcolor="@android:color/holo_blue_light" /> <view android:id="@+id/view1" android:layout_width="1dp" android:layout_height="match_parent" android:background="@android:color/holo_blue_light" /> <button android:id="@+id/buttonpropok" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:background="@android:color/transparent" android:text="ok" android:textcolor="@android:color/holo_blue_light" /> </linearlayout> </linearlayout>
you partially aware of list-item view recycling process.
the listview
component doesn't generate view each item in list. so, there won't 15
of them in case. there many can fit on screen. when scroll list, old items, no longer visible, are recycled. getview
called convertview != null
, adapter giving chance update recycled item view. done performance reasons - imagine adapter having 10000 items (not rare thing in commercial applications). should create 10000 list item views? imagine performance have while scrolling such list...
in getview()
code, update item view partially - set item title in line:
cih.gettvitemtitle().settext(ci.getdescitem());
when fresh item view created (i.e. convertview == null
) radio grouping has default selection, may fine in case.
however, when item view recycled (i.e. convertview != null
), you:
set alter listener in line:
cih.getrgitemstatus().setoncheckedchangelistener(...);
set item title:
cih.gettvitemtitle().settext(ci.getdescitem());
but never set checked radio grouping item. means, have value lastly set instance of item view - not position. should store info - in contractitem
, update when radio grouping item selected , - retrieve when convertview != null
, set selected item of radio grouping right value.
you see defect when open dialog - visible area of listview
becomes smaller soft keyboard opens. causes listview
remove unnecessary (technically: no longer visible) item views. when hide soft keyboard, listview
area becomes larger 1 time again causing create missing item views. unfortunately, don't save , restore lastly selected item of radio grouping , so, after creation newly visible items have default item selected in radio group.
android listview keyboard radio-button radio-group
Comments
Post a Comment