What I want to do is change the spinner values depends on the button clicked. For example, the spinner value will be Japan, Thailand show in the 2nd activity if I clicked the Asia button. However, the spinner value did not show up after I clicked the Asia button and start 2nd activity.
This is my code in activity 1:
spinnerDestination=findViewById(R.id.spinnerDestination);
Bundle extras=getIntent().getExtras();
int i=extras.getInt("asia",-1);
if(i==2)
{
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.asia, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDestination.setAdapter(adapter);
}
code in activity 2:
btn.add(findViewById(R.id.buttonAsia));
btn.add(findViewById(R.id.buttonEurope));
btn.add(findViewById(R.id.buttonOceanic));
for(int i=0;i<btn.size();i++)
{
int j=i;
btn.get(i).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(getApplicationContext(),MainActivity2.class);
intent.putExtra("destination", j);
startActivity(intent);
}
});
}
Did I miss anything or did it wrongly in the code. I'm new to android actually.