最近没事儿折腾android,写Fragment,写了一个工厂类如下
public class FacFragment extends Fragment {
private static final String ARG_SECTION_NUMBER = "section_number";
public static Fragment newInstance(int sectionNumber) {
Bundle args = new Bundle();
Fragment fa = new FacFragment();
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
fa.setArguments(args);
Log.v("ss-android","new Fragment"+sectionNumber);
return fa;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
int pageNo = getArguments().getInt(ARG_SECTION_NUMBER);
View rootView;
switch(pageNo){
case 1:
Log.v("ss-android", pageNo + "hehe");
rootView = inflater.inflate(R.layout.server_list, container, false);
case 2:
Log.v("ss-android",pageNo+"hehe");
rootView = inflater.inflate(R.layout.daemon_manage, container, false);
case 3:
Log.v("ss-android",pageNo+"hehe");
rootView = inflater.inflate(R.layout.log_cat, container, false);
default:
Log.v("ss-android",pageNo+"hehe");
rootView = inflater.inflate(R.layout.server_list, container, false);
}
return rootView;
}
}
大概就是根据工厂类的参数来决定Fragment的onCreate什么界面,结果出来之后都是第一个的样子...
我把三个界面分开写三个继承Fragment的类,就没有问题.....这个问题出在哪儿....求指点.....
1
aliuwr 2015-06-10 22:14:44 +08:00 1
switch 里没有 break
|
2
yangyaofei OP |