最近在使用Fragment的过程中遇到一个问题,初步是想在Fragment中创建一个构造函数,构造函数中传递两个自身需要的变量,如下
public class TestFragment extends Fragment
{
private String name;
private String passwd;
public TestFragment(String name, String passwd)
{
super();
this.name = name;
this.passwd = passwd;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.main, null);
return view;
}
}
结果eclipse报出两个错:
This fragment should provide a default constructor (a public constructor with no arguments) (com.example.TestFragment)
Avoid non-default constructors in fragments: use a default constructor plus Fragment#se
版权声明:本文为key123zhangxing原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。