Pass custom list item content to new activity when list item is clicked from a listview
First of all I want to know if this is possible. Essentially I have a listview that is being populated programatically with a custom list item view and a custom adapter. This works like a charm but the problem is that I have to sort this list in a specific way once it is populated. The values that are being put into the list are stored in String arrays. The problem is that when I sort the listview it changes the index of where I thought the values would be stored. I wan开发者_运维问答t to start a new activity with certain values found in the list view. Is this possible? I could take a string from the list item and can look it up in my arrays storing the values when that item is clicked. I can then start a new intent with extras so that I can pass this new data to the new activity. So, is it possible to extract a string from a list item?
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long arg3){
Object o=lv.getItemAtPosition(position);
UtilityClass u=(UtilityClass)o;
String s=u.getMyData();
Intent edit = new Intent(context, AnotherActivity.class);
edit.putExtra("your_identifier", Integer.toString(position));
startActivity(intent);
}});
If u have implemented onItemClickListner / onItemSelectListner then you can get a callback onItemClicked()/ onItemSelected() from there using the Adapter get the item from selected position. and the same can be sent to another activity using a bundle/extra
精彩评论