-1

Here is an example code for what i am currently doing

Class classA{

    public int changeit=1;

    Button obj;

    create(){
        Obj.addlistener(new inputlistener(){
            void touchdown(....){changeit=2;}
        });
    }

    int getvalue(){
        return changeit;
    }

}

But getvalue() never returns the changed value it always returns 1. Please suggest if there is any better way doing it or if I should create a subclass for inputListener.

mbomb007
  • 3,788
  • 3
  • 39
  • 68
tej ethical
  • 163
  • 2
  • 10

2 Answers2

0

Firstly, you have a few case errors. Typically, Java follows camel casing conventions. Secondly, because you are within an anonymous inner class you must specify which object you are referring to:

// inside the anonymous class 

classA.this.changeit = -2;
Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
0

Thank you guys for you time but I finally got the leakage and it was not related to any of the fundamentals but a human error. I had commented out the code to update the text that draws the instance on screen in bitmaptext form. Debugged it using logcat and here is my finding You can change the instances in an anonymous class directly You dont need this keyword unless the name of instance is different ofcourse.

Thank you.

tej ethical
  • 163
  • 2
  • 10