list - Android: unable to retrieve selected Item from Spinner -


in application i'm try send received inbox sms's details - sender's address, receive time new message using sms manager send message. i'm providing different format these details set according format. multiple messages selected using checkboxes. i'm providing these format in application menu setting menuitem problem sent message doesn't displaying sender's no.

in main activity:

string  address="",date="",body="", phoneno; spinner fspinner,phspinner; 

when open setting in menu alert dialog pops contain 2 spinners - fspinner body format , phspinner phone number.

case r.id.action_settings:      alertdialog.builder rdialog = new alertdialog.builder(mainactivity.this);     rdialog.settitle("select format");     layoutinflater inflater = layoutinflater.from(getapplicationcontext());     alertview = inflater.inflate(r.layout.rptsetting,null);      final spinner fspinner = (spinner)alertview.findviewbyid(r.id.fspinner);     string providers[] ={"address","time"};     arrayadapter<string> adp = new arrayadapter<string> (mainactivity.this,android.r.layout.simple_spinner_dropdown_item,providers);     fspinner.setadapter(adp);     fspinner.setonitemselectedlistener(new onitemselectedlistener() {          @override         public void onitemselected(adapterview<?> aparent, view arg1,                 int pos, long arg3) {              string selecteditem = aparent.getselecteditem().tostring();             if(selecteditem.equals("address")){                 body = "sender's address -"+address+", message body -"+reltxt.gettext().tostring();               }              else if(selecteditem.equals("time")){                     body = "message time -"+time.get(i)+", message body -"+reltxt.gettext().tostring();             }}          @override         public void onnothingselected(adapterview<?> aparent) {         }     });      final spinner phspinner = (spinner)alertview.findviewbyid(r.id.phspinner);      string number[] ={"1234","2222","0000"};     arrayadapter<string> adp1 = new arrayadapter<string> (mainactivity.this, android.r.layout.simple_spinner_dropdown_item,number);     phspinner.setadapter(adp1);     phspinner.setonitemselectedlistener(new onitemselectedlistener() {          @override         public void onitemselected(adapterview<?> phparent, view item,                 int post, long arg3) {             string phno = phparent.getselecteditem().tostring();             phlabel = phparent.getselecteditem().tostring();              if(phno.equals("1234")){                 phoneno = "1234";             }             else if(phno.equals("2222")){                 phoneno="2222";             }             else if(phno.equals("0000")){                 phoneno="0000";             }}          @override         public void onnothingselected(adapterview<?> phparent) {         }     });     rdialog.setview(alertview);     rdialog.setneutralbutton("submit", new dialoginterface.onclicklistener() {          @override         public void onclick(dialoginterface dialog, int which) {             dialog.dismiss();                }         });      alertdialog rdialog1 = rdialog.create();     rdialog1.show(); 

the checked message's stored in array list. , sms manager send details of these selected messages. phoneno selected phspinner , body selected using fspinner.

if(list.size()>0){      for(int i=0;i<list.size();i++)      {          if(list.get(i).isselected())          {              if(address.equals(""))                  address =list.get(i).getaddress();              else                  address =list.get(i).getaddress();              try               {                  smsmanager smsmgr = smsmanager.getdefault();                  smsmgr.sendtextmessage(phoneno, null, body, null, null);              }              catch (exception e)               {                  toast.maketext(this, e.getmessage()+"!\n"+"sms failed, please try again", toast.length_short).show();                  e.printstacktrace();              }          }      }  } 

try this..

string selecteditem = fspinner.getselecteditem().tostring(); 

instead of this..

string selecteditem = aparent.getselecteditem().tostring(); 

and also.

string phno = phspinner.getselecteditem().tostring(); phlabel = phspinner.getselecteditem().tostring(); 

instead of

string phno = phparent.getselecteditem().tostring(); phlabel = phparent.getselecteditem().tostring(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -