public class Header extends LinearLayout {
public Header(Context context) {
this(context,null);
}
public Header(Context context, @Nullable AttributeSet attrs) {
this(context, attrs,0);
}
public Header(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
LayoutInflater.from(context).inflate(R.layout.my_header,this,true);
View back = findViewById(R.id.my_header_back);
TextView title = findViewById(R.id.my_header_title);
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Activity.this.finish();
}
});
}
}

报错:::::'android.app.Activity' is not an enclosing class
如果你的context能保证传进来的是activity的话就可以直接用context来调用finish退出
问题已解决谢谢大家
首先 你得知道 Activity.this 代表的是什么意思