java - Reading string values under if/else commands -


im new android im gonna need little help. created 4 activities in app. first activity mainactivity. assigned listview in first activity. listview redirected second activity string says item clicked. doesn't matter item selected, redirected second activity only. diffrence values of strings passed different. used code in listview's onitemclick function:

string item  = (string) listview.getadapter().getitem(position);;                 intent = new intent(mainactivity.this, activity2.class);                     i.putextra("item_selected", item);                     startactivity(i);  

this code redirects me second activiy string without problem. in second activity there 2 options "launch type 1" , "launch type 2" inside radiobutton group , button perform function. used code inside button's onclick method determine activity go next:

intent intent = getintent();         string item = intent.getextras().getstring("item");          radiobutton launch1 = (radiobutton) findviewbyid(r.id.launch1);      //the problem code:..     if(launch1.ischecked()){         if(item=="listview_item1"){intent launch1=new intent(this, launch_activity1.class); startactivity(launch1);}     }     else{         if(item=="item 1"){intent launch2=new intent(this, launch_activity2.class); startactivity(launch2);}     } 

in eclipse shows there no errors in code. when run in emulator starts off fine till reaches second activity. when click button nothing done , not redirect new page... :( please me in constructing "if/else" statements in button...and please tell me if there better ways achive task...

thanks in advance. waiting replies....

in java, compare strings using equals() , not ==.

if(item.equals("listview_item1")) 

using == you're comparing references , not content.

use object#equals() checking if object contains same data 1 , == comparing if 2 references referencing same object.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -