how to add a widget which has two spinner items and put in a single dialog in android -
i trying design confirmation dialog has 2 lists (scrollable). 1 part shows numbers of foot , shows inches values. should in single dialog shown in image below. suggestions appreciated.
i achieved ui using following code
mycustomwidget.xml
<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <textview android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="0.5" android:text="@string/txtheight" android:id="@+id/tvheight" /> <edittext android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.50" android:id="@+id/edittext_height" android:hint="select height" android:paddingbottom="8dp" android:background="@drawable/border_bottom" /> </linearlayout>
in activity used code dialog
edittext_height.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { final dialog dialog = new dialog(profileinfo.this); dialog.setcontentview(r.layout.height_picker); dialog.show(); } });
heightpicker.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="250dp" android:layout_height="wrap_content"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/txtheight" android:layout_margintop="24dp" android:textalignment="center"/> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="@drawable/border_bottom"> <com.myapp.helperclasses.mynumberpicker android:id="@+id/footvalue" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:layout_gravity="center" android:orientation="vertical" max="7" min="4" /> <com.myapp.helperclasses.mynumberpicker android:id="@+id/inchvalue" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" android:layout_gravity="center" android:orientation="vertical" max="11" min="0" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="52dp" android:orientation="horizontal"> <textview android:id="@+id/textview_cancel" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="36dp" android:layout_margintop="8dp" android:layout_marginleft="24dp" android:text="@string/txtcancel" android:textalignment="center" android:textcolor="@color/blue"/> <textview android:id="@+id/textview_okay" android:layout_width="0dp" android:layout_weight="0.5" android:layout_height="32dp" android:layout_margintop="8dp" android:layout_marginleft="8dp" android:layout_marginright="8dp" android:text="@string/txtokay" android:textalignment="center" android:textcolor="@color/blue"/> </linearlayout> </linearlayout>
you can use numberpicker way
<numberpicker android:id="@+id/numberpicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerinparent="true" />
java
public class mainactivity extends activity { numberpicker np; textview tv1, tv2; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); np = (numberpicker) findviewbyid(r.id.numberpicker1); tv1 = (textview) findviewbyid(r.id.textview2); tv2 = (textview) findviewbyid(r.id.textview3); np.setminvalue(0); np.setmaxvalue(10); np.setwrapselectorwheel(false); np.setonvaluechangedlistener(new onvaluechangelistener() { @override public void onvaluechange(numberpicker picker, int oldval, int newval) { // todo auto-generated method stub string old = "old value : "; string new = "new value : "; tv1.settext(old.concat(string.valueof(oldval))); tv2.settext(new.concat(string.valueof(newval))); } }); }
Comments
Post a Comment