i have 2 spinners with 10 values each,
now what i want is when the user selects the 2 values returns a specific picture on another activity called “YourPath”
here is the code for the first activity
private Spinner spinner1, spinner2;
private Button btnSubmit;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.locationlist);
addListenerOnButton();
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
}
public void addListenerOnButton() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
btnSubmit = (Button) findViewById(R.id.button1);
btnSubmit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
AlertDialog alertDialog = new AlertDialog.Builder(
LocationList.this).create(); // Read Update
alertDialog.setTitle("Confirm Message");
alertDialog.setMessage("You are in "
+ String.valueOf(spinner1.getSelectedItem())
+ "\nAnd You are going to "
+ String.valueOf(spinner2.getSelectedItem()));
alertDialog.setButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
launchIntent();
}
});
alertDialog.setButton2("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
});
alertDialog.show();
}
private void launchIntent() {
Intent it = new Intent(LocationList.this, YourPath.class);
it.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(it);
}
});
}
}
now do i need a database to do that !!!
do you have any ideas about how can i do that !!!!
thanks
You do not necessarily need a database at all. In fact, the only reason you would is if you want to dynamically change the images that are possible for users to end up on “your path”.
If you can provide all of the images while creating the app, simply put them all in the /Drawable folder, and then you will access the one you want in the YourPath Activity.
I would grab these values and put them in a variable to use them like this:
Then, I would stick a couple of string values into the intent you are sending to the YourPath activity. You will do that in the launchIntent method like this:
Then, in your YourPath class, grab these values like this:
You will then do some if-else (or preferably switch) statement to figure out which image to show
Then add your my_path layout file to res/layout folder
You should now be able to access the image view in your myPath activity, just dont forget to set the content view: