I don't know if you've resolved your problem, but if you haven't, here is what you can do to make it work. You should use OnItemClickListener() instead of OnItemSelectedListener(). I couldn't find the difference between those two in AdapterView, but I can say that it (OnItemSelectedListener()) was never invoked while debugging your code. Here is the replacement:
textView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
if(index == 1){
Intent i = new Intent (MainActivity.this, SecondActivity.class);
i.putExtra("KEY", presidents[index]);
startActivity(i);
}
}
});
Also keep in mind that index in onItemClick() is the position of item clicked. So if you click the first item from the drop down list (index=0) which is, say, "Bill Clinton", you put "Rahul" as extra for the Intent.
EDIT according to your new question. Do as follows:
textView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
String president = ((TextView) view).getText().toString();
Intent intent = null;
if (president.equals("John F. Kennedy"))
intent = new Intent (MainActivity.this, KennedyActivity.class);
if (president.equals("Lyndon B. Johnson"))
intent = new Intent (MainActivity.this, JohnsonActivity.class);
if (president.equals("Richard Nixon"))
intent = new Intent (MainActivity.this, NixonActivity.class);
if (president.equals("Gerald Ford"))
intent = new Intent (MainActivity.this, FordActivity.class);
if (president.equals("Jimmy Carter"))
intent = new Intent (MainActivity.this, CarterActivity.class);
if (president.equals("Ronald Reagan"))
intent = new Intent (MainActivity.this, ReaganActivity.class);
if (president.equals("George H. W. Bush"))
intent = new Intent (MainActivity.this, SrBushActivity.class);
if (president.equals("Bill Clinton"))
intent = new Intent (MainActivity.this, ClintonActivity.class);
if (president.equals("George W. Bush"))
intent = new Intent (MainActivity.this, JrBushActivity.class);
if (president.equals("Barack Obama"))
intent = new Intent (MainActivity.this, ObamaActivity.class);
if (intent != null) {
intent.putExtra("KEY", president);
startActivity(intent);
}
}
});