I have 2 activities.
The first activity is an activity that parses JSON data from a server to a ListView and the second activity is an activity that displays the data from selected values in the ListView.
Here’s the onClick method of my 1st activity :
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(this, userList,
R.layout.listitemviewall,
new String[] { "namaresto", "alamatresto"},
new int[] {R.id.name, R.id.address});
setListAdapter(adapter);
/**
* select resto
*/
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/**
* move to the next activity
* */
String namanya = ((TextView) findViewById(R.id.name)).getText().toString();
String alamatnya = ((TextView) findViewById(R.id.address)).getText().toString();
//Starting a new Intent
Intent nextScreen = new Intent(getApplicationContext(), InfoTab.class);
//Sending data to another Activity
nextScreen.putExtra("name", namanya);
nextScreen.putExtra("address", alamatnya);
// starting new activity
startActivity(nextScreen);
}
});
And here is the second activity :
TextView txtname = (TextView) findViewById(R.id.textTEST1);
TextView txtaddress = (TextView) findViewById(R.id.TextTEST2);
//displaying data from previous activity
Intent i = getIntent();
// Receiving the Data
String name = i.getStringExtra("name");
String address = i.getStringExtra("address");
// Displaying Received data
txtname.setText(name);
txtaddress.setText(address);
The Result, the second Activity always displays THE FIRST RECORD! Even if i clicked the second or other record in the ListView.
How can i get my code to display the correct record that is selected in the ListView?
try changing these lines:
to:
tell me if that works for you…