Marcel Bro
Marcel Bro

Reputation: 5025

Android: How to call a parent Activity method from a child custom view?

Please, give me a hint how to solve this situation:

I have two custom views in my Activity and I'd like to call an Activity method after clicking a button in one of custom views (Y).
I can get the X view from parent Acitivity by findViewById() and call it's public method. But how can I let the parent Acitivy know that the button was pressed?

Do I have to pass Activity reference to view Y to call an Activity method from OnClickListener?

example Thank you!

Upvotes: 0

Views: 2236

Answers (1)

MAC
MAC

Reputation: 15847

button = (Button)customviewY.findViewById(R.id.btnClick);

button.setOnClickListener(new OnClick..(){
    onClick(View v)
    {
        textView= (TextView)customviewY.findViewById(R.id.txtView);
        textView.setText("");
    }
});

Upvotes: 2

Related Questions