I have defined a model class:
public class MyObject {
...
}
In my activity, I get this object from SERVICE layer. Everything works fine at this point, my only question is, in Activity, if I set setOnClickListener to a TextView, how can I access myObject? What I mean is showing in the following code:
//my custom object
MyObject obj = SERVICE.getObject();
TextView tx = new TextView(this);
tx.setText("Click me");
tx.setOnClickListener(
new OnClickListener(){
@Override
public void onClick(View v){
//how to access obj here?
}
}
);
In the above code, I can not access obj inside onClick(View v) function, how to get rid of it to access obj inside onClick(View v) ?
If you have an ID, you can set that ID on the tag field and retrieve it in the onclick:
You can store an arbitrary object, so you could potentially store the whole object there.