I have a ListView. It contains JSON I pulled from the web. I want each item in the ListView to go to the same activity and the same TextView. That's easy enough on the face of it.
However I want the TextView to show different items depending on what the user clicked on. In fact better make it two TextViews because one of them has a link. There's two lines of text, one is a link.
So if the user presses the first list item, they go to this activity and be presented with information_01. If the same user backs out and then goes to the second list item it should go to the very same activity and show information_02, and so on.
I'll show you what I have so far, it's nothing special:
title.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
switch (position) {
case 0:
Driver p = (Driver) title.getItemAtPosition(position);
Intent i = new Intent(MainActivity.this, DataActivity.class);
i.putExtra("one_id", p.id);
i.putExtra("one_link", p.link);
MainActivity.this.startActivity(i);
case 1:
Driver p1 = (Driver) title.getItemAtPosition(position);
Intent i1 = new Intent(MainActivity.this, DataActivity.class);
i1.putExtra("two_id", p1.id);
i1.putExtra("two_link", p1.link);
MainActivity.this.startActivity(i1);
case 2:
break;
}
Hopefully this is possible because creating a million activities for each list item is a pain in the arse. Like I said one of them is a link which I need to send to another page on my app. So please bare in mind that showing it and clicking on it is needed.
Would great appreciate some help on the matter. Thanks in advance.
EDIT: My DataActivity.class
public class DataActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_list);
//Case 0
Intent intent0 = getIntent();
String link0 = intent0.getStringExtra("one_link");
String id0 = intent0.getStringExtra("one_id");
TextView data0 = (TextView) findViewById(R.id.case0Text);
data0.setText("ID: " + id0 + "\n\n Click here: " + link0);
//Case 1
Intent intent1 = getIntent();
String id1 = intent1.getStringExtra("two_id");
String link1 = intent1.getStringExtra("two_link");
TextView data1 = (TextView) findViewById(R.id.case1Text);
data1.setText("ID: " + id1 + "\n\n Click here: " + link1);
}
}