简体   繁体   中英

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?

例 Thank you!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM