Reputation: 4827
Is there a way to get a pointer of activity which containing object of action Listener?
code snippet:
public class ActivityAsContainer exteneds Activity{
public static ActivityAsContainer _brokeTheAbstractBarier;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_brokeTheAbstractBarier = this;
setContentView(R.layout.SomeBigLie);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
brokeTheAbstractBarier.dance;
}
}
}
Is there a better way to pass the activity over to the action listener, then use a static global that could break if the object is created twice, and could a view be created twice and still live?
Upvotes: 0
Views: 105
Reputation: 5260
Hope you will be able to solve after using this line
_brokeTheAbstractBarier = YoursMainActivity.this;
instead of
_brokeTheAbstractBarier = this;
or you can use
ActivityAsContainer.this
which is
button.setOnClickListener(new View.OnClickListener() {
ActivityAsContainer.this.dance;
}
Upvotes: 1
Reputation: 35661
Just use
ActivityAsContainer.this
e.g
button.setOnClickListener(new View.OnClickListener() {
ActivityAsContainer.this.dance;
}
Upvotes: 2
Reputation: 22661
It should not be static.
You can use this definition in OnCreate
and then use myActivity
in the listener.
final Activity myActivity=this;
Upvotes: 1