Sunday, April 28, 2013

[android help] Android Search Using Fragments

Android Search Using Fragments - Stack Overflow








Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I need to do an android search using fragments and have been looking at this: Android search with Fragments


I have a couple of questions, however, regarding the 1st answer.


I do not want a new page to pop up; I want the search results to be populated within a listview of the current fragment I am within. Is that possible?


I'm not sure what code to write after:



/**
* Performs a search and passes the results to the container
* Activity that holds your Fragments.
*/

public void doMySearch(String query) {
// TODO: implement this
}


How do I pass my results to a 'container activity' that holds my fragments? Would that be my MainActivity (that's where the code of all my fragments is located)?


























'Container Activity' doesn't specifically your MainActivity as this is the name a lot of devs and example code gives to their landing/home activity.


'Container Activity' refers to the Activity to which your ListView (ListFragment?) and Search Fragment belong.


To post the results (via your TODO code), get the parent Activity (getActivity()) and implement a method on the parent Activity that gets the fragment with the ListView and passes the data to it. You may want to have a method on the ListView that handles this rather than putting it on the Activity. (I like to think of a parent Activity as a delegator)




















default







.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...