I need to start a new activity once the user clicks in a button which is rendered in a FrameLayout. It renders the button which I want the user to click, but of course it’s not doing anything right now.
The code of the class is the following, but I can’t call the startActivity(intent).
public class TopBarView extends FrameLayout {
private ImageView mLogoImage;
private Button mInfoButton;
public TopBarView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public TopBarView(Context context) {
super(context);
init();
}
public TopBarView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.top_bar, null);
mLogoImage = (ImageView) view.findViewById(R.id.imageLogo);
mInfoButton = (Button) view.findViewById(R.id.infoButton);
mInfoButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// We load & render the view for the information screen
// Intent i = new Intent();
// i.setClass(getContext(), MeerActivity.class);
// startActivity(i);
}
});
addView(view);
}
}
Thanks a lot in advance!
Change :
To :
Note : Might be better to assign the onclicklistener via the activity you are using so the TopBarView is a bit more reusable in case you ever want to use something other than MeerActivity as a target. No biggy tho.