sms - Android Number sendMessage to New Number -
i have 2 classes 1 selecting pets called selectpetsscreen has button called change number .this button allows user change number message sent new number (device) problem tried make new value of number 1 written in textedit
number=input.tostring();
but says number cannot resolved variable (but set public in other class) next try included in code , still have same number try created object calls setnumber() method still no hope :(
selectpetsscreen.java package com.set.petshome;
import android.app.activity; import android.app.alertdialog; import android.content.*; import android.media.mediaplayer; import android.os.bundle; import android.text.editable; import android.view.*; import android.widget.button; import android.widget.edittext; import android.widget.imagebutton; public class selectpetsscreen extends activity { fishtank ii=new fishtank(); imagebutton fbutton,sbutton,tbutton; private mediaplayer mp0,mp1; string value; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.selectscreen); //menu startup sound code mp0=mediaplayer.create(this,r.raw.menu); mp0.start(); //end menu sound code //change no. button button cn = (button) findviewbyid(r.id.cn); cn.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { alertdialog.builder alert = new alertdialog.builder(selectpetsscreen.this); /*voice final mediaplayer mp1=mediaplayer.create(getbasecontext(),r.raw.menu); mp1.start(); //end voice */ //test alert.settitle("change number:"); //alert.setmessage("message"); // set edittext view user input final edittext input = new edittext(selectpetsscreen.this); alert.setview(input); alert.setpositivebutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { value = input.gettext().tostring(); fishtank a=new fishtank(); a.setnumber(value); // value! } }); alert.setnegativebutton("cancel", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int whichbutton) { dialog.cancel(); // canceled. } }); //end test alert.show(); } }); //end change no. button //button fishtank listener start fbutton = (imagebutton) findviewbyid(r.id.imagebutton1); //listening button event fbutton.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { //voice mp1=mediaplayer.create(getbasecontext(),r.raw.menu); mp1.start(); //end voice //starting new intent intent nextscreen = new intent(getapplicationcontext(), fishtank.class); startactivity(nextscreen); } }); //button fishtank listener end //button cats listener start sbutton = (imagebutton) findviewbyid(r.id.imagebutton2); //listening button event sbutton.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { //voice final mediaplayer mp1=mediaplayer.create(getbasecontext(),r.raw.menu); mp1.start(); //end voice //starting new intent intent nextscreen2 = new intent(getapplicationcontext(), csoon.class); startactivity(nextscreen2); } }); //button cats listener end //button dogs listener start tbutton = (imagebutton) findviewbyid(r.id.imagebutton3); //listening button event tbutton.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { //voice final mediaplayer mp1=mediaplayer.create(getbasecontext(),r.raw.menu); mp1.start(); //end voice //starting new intent intent nextscreen3 = new intent(getapplicationcontext(), dsoon.class); startactivity(nextscreen3); } }); //button dogs listener end } }
and here other class containing method setnumber() , number variable
package com.set.petshome; import android.app.activity; import android.content.intent; import android.media.mediaplayer; import android.os.bundle; import android.telephony.smsmanager; import android.view.menu; import android.view.view; import android.widget.button; import android.widget.compoundbutton; import android.widget.togglebutton; public class fishtank extends activity { togglebutton toggle1,toggle2,toggle3; public static bundle bundle = new bundle(); public string number = "+12020000000";// recipient's mobile number public void setnumber(string a) { number=a.tostring(); } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.ftank); final string[] messages = new string[]{"feeder on", "feeder off","led on","led off","filter on","filter off"}; final smsmanager sm = smsmanager.getdefault(); final mediaplayer on,off; //menu startup sound code on=mediaplayer.create(this,r.raw.on); off=mediaplayer.create(this,r.raw.off); //end menu sound code //start togglebutton1 toggle1 = (togglebutton) findviewbyid(r.id.togglebutton1); toggle1.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { on.start(); sm.sendtextmessage(number, null, messages[0], null, null); } else { off.start(); sm.sendtextmessage(number, null, messages[1], null, null); } } }); //end togglebutton1 //start togglebutton2 toggle2 = (togglebutton) findviewbyid(r.id.togglebutton2); toggle2.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { on.start(); sm.sendtextmessage(number, null, messages[2], null, null); } else { off.start(); sm.sendtextmessage(number, null, messages[3], null, null); } } }); //end togglebutton2 //start togglebutton3 toggle3 = (togglebutton) findviewbyid(r.id.togglebutton3); toggle3.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() { public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) { if (ischecked) { on.start(); sm.sendtextmessage(number, null, messages[4], null, null); } else { off.start(); sm.sendtextmessage(number, null, messages[5], null, null); } } }); //end togglebutton3 } //save toggle state @override public void onpause() { super.onpause(); bundle.putboolean("togglebuttonstate", toggle1.ischecked()); bundle.putboolean("togglebuttonstate2", toggle2.ischecked()); bundle.putboolean("togglebuttonstate3", toggle3.ischecked()); } @override public void onresume() { super.onresume(); toggle1.setchecked(bundle.getboolean("togglebuttonstate")); toggle2.setchecked(bundle.getboolean("togglebuttonstate2")); toggle3.setchecked(bundle.getboolean("togglebuttonstate3")); } //end save toggle state }