我有一个Fragment
,其中包含TextView
,EditText
,ImageView
和Framelayout
。在Framelayout
的{{1}}中,我使用以下代码将onCreate()
替换为Framelayout
:
Fragment
现在我得到一个public class OneFragment extends Fragment {
private static final String TAG = "OneFragment";
public static final String DATA = "SalesData";
private ViewGroup container;
private LayoutInflater inflater;
private MyData myData;
@BindView(R.id.start_task)
Button start_task;
@BindView(R.id.easy_flip)
EasyFlipView easyFlipView;
@BindView(R.id.frame_container)
FrameLayout frameLayout;
BackFragment blankFragment = new BackFragment();
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
this.container = container;
this.inflater = inflater;
return initializeView();
}
private View initializeView() {
View view = inflater.inflate(
R.layout.view_pager_fragment, container, false);
ButterKnife.bind(this, view);
if (getArguments() != null) {
myData = (MyData)getArguments().getSerializable(DATA);
}
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.frame_container, blankFragment, "NewFragmentTag");
ft.commit();
Button back_task =blankFragment.getView().findViewById(R.id.back_task);
back_task.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
easyFlipView.flipTheView();
}
});
start_task.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
easyFlipView.flipTheView();
}
});
return view;
}
public void flipView(){
easyFlipView.flipTheView();
}
}
,说找不到来自RuntimeExpcetion
的视图。此BlankFragment
上有一个单击的按钮,我需要呼叫BlankFragment
。我应该怎么做。
答案 0 :(得分:1)
创建回调接口并在OneFragment类中实现它,并从BackFragment的onclick侦听器调用回调的方法