Search code examples
javaandroidclicklistener

how to access variable inside OnClickListener


I have a double that I created inside one on click listener and I want to access it in a separate on click listener in the same java file. every time I type the variable name it comes up in red, is it possible to do this?


Solution

  • Yes, declare it as a global variable of your class.

    class MainActivity
    {
        String editableString;
    
        public void onCreate() { ... }
    }