Reputation: 5197
Right now I have two activities. My goal is to allow the user to type something in on the first activity and click submit. It then uses search query on a site and pulls in the json object. Right now I have it listing the names within the jsonarray. What I want to allow the user to do is click on one of these items in the list, and the app will go fetch more detailed information from a different URL.
What is the best way to accomplish this? I already have the search box working, the linked list generating with the names I need, and also have the onclicklistener for each list item. How can I enable my app to go fetch something more detailed depending on what they click? The information needed to go fetch something is dependent on either what the specific list item says or if I can somehow embed a different action for each list item when it is dynamically created.
Upvotes: 0
Views: 144
Reputation: 7350
Rather than using onClickListener you should use OnItemSelectedListener then in
@Override
public void onItemSelected(AdapterView<?> parent,View v, int position, long row) {
//you are given the position in the adapterview for the selected item here. get it and do something
//like
Intent yourIntent=new Intent(Context, YourOtherAcitivty.class);
yourIntent.putExtra("something",YourObjectArray.get(position));
startActivityForResult(yourIntent,0);
//OR
yourMethodToGetMoreData(position);
//etc...
}
Upvotes: 1