I have designed an activity in which there is a listView. I want that on click of the list item a new Activity should start and it should contain detail data related to the ListItem clicked.Please help me out in doing this.Thanks in advance.
Asked
Active
Viewed 3,747 times
4 Answers
3
While starting an activity use putExtra
to send data to another activity
Intent i = new Intent(this, SecondActivity.class);
i.putExtra("listitemselected", listitemvalue);
startActivity(i);
In SecondActivity.java use getStringExtra
to get the values.
Intent i = getIntent();
String listItem = i.getStringExtra("listitemselected");

KillerFish
- 5,042
- 16
- 55
- 64
2
In the action handler start the new activity with putextra you can add some data
Intent intent = new Intent(ShowLocation.this, ListLocationActions.class);
intent.putExtra("infoName1", myData);
intent.putExtra("infoName2", MyData2);
startActivity(intent);
in the new activity:
String myData = getIntent().getStringExtra("infoName1");
String myData2 = getIntent().getStringExtra("infoName2");

BadSkillz
- 1,993
- 19
- 37
1
In your onItemClick. Try something like this; you can send id of the item if your are using Sqlite database. or your can send the Object (If Serializable) from the Object array at specific postion. The postion will be the index of the selected List Item as well as index of the Object in that specific array, Or it may be a String.
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id)
{
Intent status = new Intent(CurrentActivity.this,NextActivity.class );
status.putExtra("_ID", id);
//Or
status.putExtra("OBJECT", mArray[position]);
startActivity(status);
}

Adil Soomro
- 37,609
- 9
- 103
- 153
0
String temp = listView(v.getId()).getText().toString();
Intent i1 = new Intent(currentAct.this,nextAct.class);
i1.putExtra("listitem",temp);
startActivity(i1);
listView() ==>It is having all the listItem that you are displayed on listItem

Sumant
- 2,775
- 2
- 22
- 30