从片段呼叫活动的按钮clickListener? [英] Call Button clickListener of activity from fragment?
本文介绍了从片段呼叫活动的按钮clickListener?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有我的活动包含片段里面的按钮。从片段之一,我需要调用按钮,按钮clickListener并传递一个意图与群众演员到另一个活动。我怎样才能做到这一点?我搜索了很多本,但无法找到这个合适的解决方案。
I have a button inside my activity which contain fragments. From one of the fragment I need to call button, button clickListener and pass an intent with extras to another activity. How can I do this? I searched a lot for this but couldn't find an appropriate solution for this.
推荐答案
实施onClickListener在活动按钮:
Implement the onClickListener for the button in the activity:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// get the fragment from the fragment manager
Fragment frag = getFragmentManager().findFragmentByTag("FRAGMENT TAG");
Bundle extras = frag.getExtrasForNewActivity();
/// Your code here this is for Activity
Intent intent=new Intent(getActivity(),Second.class);
intent.putExtras(extras);
startActivity(intent);
}
});
和片段中,创建一个方法,像这样:
and in the fragment, create a method like so:
public Bundle getExtrasForNewActivity()
{
/// return a bundle with values
}
这篇关于从片段呼叫活动的按钮clickListener?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文