Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void addListenerOnSpinnerItemSelection1() {
    spinvisitingPlace = (Spinner) findViewById(R.id.spinvisitingPlace);
    spinvisitingPlace.setOnItemSelectedListener(new CustomOnItemSelectedListener());
    if (spinvisitingPlace.equals("Rajbari")) {

        Intent intent = new Intent(MainActivity.this,ActivityTajhat.class);
        startActivity(intent);

  }
    else {
      Toast.makeText(MainActivity.this, "string",1000).show();
  }



when i run it at first its show the toast message but when i select my "Rajbari" value..it's don't give me any answer. please help me
Posted
Comments
Krunal Rohit 5-Mar-14 15:45pm    
can you post the items of Spinner ?

-KR

Hi, The code you posted ,is wrong. the code if(spinvisitingPlace.equals("Rajbari")) is wrong.
Just put this line inside of onItemclicklistener(AdapterView
and get the value from that of using

String string=arg0.getItemAtPosition(arg2).toString().trim();
Next you will compare this string with

if(string.equals("Rajbari))
{
Intent intent = new Intent(MainActivity.this,ActivityTajhat.class);
startActivity(intent);
}
 
Share this answer
 
Where's onItemSelected method in your code
Java
public class SpinnerActivity extends Activity implements OnItemSelectedListener {
    ...

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        // An item was selected. You can retrieve the selected item using
        // parent.getItemAtPosition(pos)  >> this will solve your problem
    }

    public void onNothingSelected(AdapterView<?> parent) {
        // Another interface callback
    }
}


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900