Inside OnClickListener I cannot access a lot of things – how to approach?

Replace this in your code with MyActivity.this where MyActivity is the class name of your Activity subclass.

Explanation: You are creating an anonymous inner class when you use this part of your code:
new OnClickListener() {
Anonymous inner classes have a reference to the instance of the class they are created in. It looks like you are creating it inside an Activity subclass because findViewById is an Activity method. Activity’s are a Context, so all you need to do is use the reference to it that you have automatically.

Leave a Comment