In my activity I have two listviews with some data. On first listview selected row will be highlighted on click and on click on 2nd listview new activity starts. I want to send the highlighted row data of first listview and clicked row of 2nd listview data on next activity. How can Iachieve that?
Asked
Active
Viewed 121 times
0

Tunaki
- 132,869
- 46
- 340
- 423

Suruchi Mahajan
- 33
- 5
-
Possible duplicate of [How to pass object from one activity to another in Android](http://stackoverflow.com/questions/2736389/how-to-pass-object-from-one-activity-to-another-in-android) – Rami Nov 12 '15 at 13:25
-
I had seen that solutions but didn't work for me that's why I ask the question again – Suruchi Mahajan Nov 12 '15 at 13:28
-
How did it not work for you? Please give more details. – Kelly Keller-Heikkila Nov 12 '15 at 13:29
-
It should work, post your code. – Rami Nov 12 '15 at 13:29
-
Is there any way to transfer two listview data on other activity without using serialzable and parceable – Suruchi Mahajan Nov 12 '15 at 13:31
1 Answers
0
supposing your lists are named list1 & list2, add to your list2 onItemClickListener that should looks something like this :
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
String highlightedItem = (String)list1.getSelectedItem();
String clickedItem = (String)list2.getItemAtPosition(position);
Intent intent = new Intent(FirstAcivity.this, SecondActivity.class);
intent.putExtra("highlightedItem", highlightedItem);
intent.putExtra("clickedItem", clickedItem);
startActivity(intent);
}
and then in your Second Activity you can receive the items like this :
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
Intent intent = getIntent();
if (intent != null){
String highlightedItem = intent.getStringExtra("highlightedItem");
String clickedItem = intent.getStringExtra("clickedItem");
}
}
I have assumed your list items are of type String but you can apply the same logic for any other type. In case your want to send object not just primitives you need to make your objects implements Serializable or Parcelable interface.

Mulham Raee
- 313
- 1
- 8
-
-
If I also want to show the result on listviews on next activity then also I need to do the same thing. Scenario is that I am volley request to show data on two listviews and the highlighted row on 1st listview and clicked row on 2nd listview, want to send that data on next activity and representing that also in two different listviews. – Suruchi Mahajan Nov 13 '15 at 08:23
-
Can you please be more clear about what you need! and if this answer worked for you please accept it – Mulham Raee Nov 13 '15 at 14:07
-
I am using volley for json data and shown that data on two different listviews. And when click on 1st listview row will be highlighted and when click on 2 nd listview new activity starts. I want that the 1st listview highlighted row data and 2nd listview clicked row data on next activity listview. – Suruchi Mahajan Nov 13 '15 at 14:14
-
I tried your answere firstly it showed me error for 2nd listview data cannot bind , after resolving this it doesn't show highlighted listview data – Suruchi Mahajan Nov 13 '15 at 14:16