String[] songList = {
"1",
"2",
"3",
};
Spinner sp;
TextView selection;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<Object> aa = new ArrayAdapter<Object>(
this,
android.R.layout.simple_spinner_item,
songList);
aa.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
spin.setAdapter(aa);
}
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
selection.setText(songList[position]);
String song = songList[position];
Intent intent = new Intent(this, Tabview.class);
Bundle b = new Bundle();
b.putString("song", song);
intent.putExtras(b);
startActivityForResult(intent, 0);
}
public void onNothingSelected(AdapterView<?> parent) {
selection.setText("");
}
{
I have this code written right now. Pretty much what I’m trying to do is use the spinner selection to open a new activity (which I have done) BUT, I am also trying to use httpget to download information based on a link.
So, for ex:
If I press “1”, it will open up a new activity, then it will call an httpget method, then it will download the data based on what you pressed. and that data will change for each option you press (EX. “1”= google.com, “2”=facebook.com, etc.) and then that data will be displayed in the activity.
I also want to only use ONE activity to display the data for each selection.
Also in my “Tabview.class” I have:
Bundle b = new Bundle();
String song = b.getString("song");
Thanks for any help!
What exactly is the error you get? The code seems to work. If you wanted to choose something according to the selection, you can use a simple if condition on the bundled string. Or if the issue here is about http get, take a look at the documentation here. You can use an AyncTask to make an http request without blocking.
For a reference, I have attached my code which just an improved version of your code.
And in the other activity,
Make sure you add your activity in the Android Manifest file.
Thanks