As shown in your code "query" is declared as a local variable inside search method ( in the stack ), so in all the other methods you are trying to use an undeclared variable.
You MUST declare query as a member of the class, like a global variable, but inside the class itself.
Try declaring it i.e. on the private or protected section of class declaration, at it must work fine.
Bookmarks