Say I have this code, which creates an ImageView and puts it into a linearlayout.
Also I have an OnClick listener that’s supposed to, upon click, remove the old imageview and replace it with a new one.
But strangely it shows “The constructor ImageView(new View.OnClickListener(){}) is undefined”.
final LinearLayout LinLayBtn = new LinearLayout(this);
ImageView ivBtn = new ImageView(this);
ivBtn = mkatt.makeKey( ivBtn, btnHue, btnSat, buttonScale, buttonScaleCnt, textAdjust, btnTextColor, buttonText, btnOpa, spacingLR, spacingTB);
LinLayBtn.addView(ivBtn);
LinLayBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LinLayBtn.removeAllViews();
ImageView ivBtn = new ImageView(this); // The constructor ImageView(new View.OnClickListener(){}) is undefined
ivBtn = mkatt.makeKey( ivBtn, btnHue, btnSat, buttonScale, buttonScaleCnt, textAdjust, btnTextColor, buttonText, btnOpa, spacingLR, spacingTB);
LinLayBtn.addView(ivBtn);
}
});
Any ideas what to do with it?
Thanks!
thisin the ImageView constructor is the OnClickListener instance. You need to pass it the instance of your Activity class (i.e. the outer class). Say your outer class is calledMyActivity, then you should passMyActivity.thisto the ImageView constructor