java - cant add ImageView in a subclass -


i can add imageview programatically main class. can't subclass. when try imageview iv = new imageview(this) getting error imageview (android.content.contex) in imageview can not applied (...mainactivity.mysubclass)

code:

public class mainactivity extends activity {  ... class mysubclass {     imageview iv;     mysubclass(view v) // create object onclick method     {         iv = new imageview(this);     } } // end of subclass  } // end of main 

since don't have code posted, have guess.

instead of using this keyword, try use mainactivity.this.

if have subclass in activity, use context of running activity.


Comments