java - how to update seekbar using a edittext -
i read example of how show progres of seekbar edittext web page:
now problem how change seekbar if introduce number inside edittext box? help
if can acces web page post code:
main:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <textview android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <edittext android:id="@+id/edittext1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_margintop="94dp" > <requestfocus /> </edittext> <seekbar android:id="@+id/seekbar1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentleft="true" android:layout_below="@+id/textview1" android:layout_margintop="38dp" /> </relativelayout>
and java code:
import android.app.activity; import android.os.bundle; import android.widget.edittext; import android.widget.seekbar; import android.widget.seekbar.onseekbarchangelistener; public class seekbaractivity extends activity { /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); seekbar sb=(seekbar) findviewbyid(r.id.seekbar1); final edittext et=(edittext) findviewbyid(r.id.edittext1); sb.setonseekbarchangelistener(new onseekbarchangelistener() { @override public void onstoptrackingtouch(seekbar seekbar) { } @override public void onstarttrackingtouch(seekbar seekbar) { } @override public void onprogresschanged(seekbar seekbar, int progress, boolean fromuser) { //---change font size of edittext--- et.settext(string.valueof(progress)); } }); } }
a quick example :
//et , sk class variables et=(edittext)findviewbyid(r.id.edittext); sk = (seekbar)findviewbyid(r.id.seekbar); et.addtextchangedlistener(new textwatcher() { @override public void beforetextchanged(charsequence s, int start, int count, int after) { } @override public void ontextchanged(charsequence s, int start, int before, int count) { } @override public void aftertextchanged(editable s) { try{ //update seekbar value after entering number sk.setprogress(integer.parseint(s.tostring())); } catch(exception ex) {} } });
Comments
Post a Comment