Ninoop p george Ninoop p george - 1 year ago 70
Android Question

Call a method with element as parameter

I have this:

final Button myButton = (Button) findViewById(;

How can I pass
into a method as a parameter? So I can use it inside a method to do something.

Like, I can call my method
and it hides the given object.
So, how can i declare the method with the element as the parameter?

Answer Source

Well, you'd better refer to documentation and Java tutorials.

But in your case, you can try:

public class VisibilityManager {
    public static void hide(View view){

    public static void show(View view){

And then call this like:

final Button mybutton = (Button) findViewById(;
// you can do it because `Button extends View`.

Read more: View#setVisibility(int)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download