【发布时间】:2015-09-06 14:57:58
【问题描述】:
我有一个具有三种布局的选项卡视图。每个布局使用框架布局分为 4 个部分,每个部分都有一个按钮。所以总共有12个按钮。由于 View 是 First Layout,所以其他两种布局中的按钮返回空指针异常。我尝试包含在 XML 中,但按钮被合并并且应用程序运行。任何解决方案。日夜工作。
View rootView = inflater.inflate(R.layout.fragment_main,container,false);
View rootView = inflater.inflate(R.layout.fragment_2,container,false);
View rootView = inflater.inflate(R.layout.fragment_3,container,false);
b1=(Button)rootView.findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View a){...}
});
Fragment_main 中的按钮正在运行,但 fragment_2 和 fragment_3 中的按钮返回空指针异常。
注意:我使用了 Eclipse 的选项卡布局。
提前感谢您的帮助
【问题讨论】: