Skip to content

Instantly share code, notes, and snippets.

@liliycode
Created March 20, 2017 21:00
Show Gist options
  • Save liliycode/50246841d81a65ec177283ec0a488b52 to your computer and use it in GitHub Desktop.
Save liliycode/50246841d81a65ec177283ec0a488b52 to your computer and use it in GitHub Desktop.
java for android
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Spinner s = (Spinner) findViewById(spinner);
s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
if (s.getSelectedItem().toString().equals("Mark Twain"))
Toast.makeText(MainActivity.this, ("Books by Mark Twain include: The prince and the pauper, " +
"The adventures of Tom Sawyer and the adventures of Huckleberry Finn.").toString(), Toast.LENGTH_LONG).show();
else if (s.getSelectedItem().toString().equals("Toni Morrison"))
Toast.makeText(MainActivity.this, "Books by Toni Morrison include: Beloved, The bluest eye and Song of Solomon. ".toString(), Toast.LENGTH_LONG).show();
else if (s.getSelectedItem().toString().equals("Ernest Hemingway"))
Toast.makeText(MainActivity.this, "Books by Ernest Hemingway include: From whom the bell tolls, The old man and the sea and The sun also rises.".toString(), Toast.LENGTH_LONG).show();
else if (s.getSelectedItem().toString().equals("John Steinbeck"))
Toast.makeText(MainActivity.this, "Books by John Steinbeck include: East of Eden, Of mice and men and The grapes of wrath.".toString(), Toast.LENGTH_LONG).show();
else
{
Toast.makeText(MainActivity.this, "Selected an item".toString(), Toast.LENGTH_LONG).show();
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment