我怎么知道哪个选项卡在我的
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 函数???
以下代码仅适用于拳头导航,但之后在每个选项卡中显示最后一个布局。
public final class RobozoxFragment extends Fragment {
private static final String KEY_CONTENT = "RobozoxFragment:Content";
private static int currentPosition = 100;
public static RobozoxFragment newInstance(String content,int position) {
currentPosition = position;
RobozoxFragment fragment = new RobozoxFragment();
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 20; i++) {
builder.append(content).append(" ");
}
builder.deleteCharAt(builder.length() - 1);
fragment.mContent = builder.toString();
return fragment;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View myFragmentView;
if(currentPosition == 1){
myFragmentView = inflater.inflate(R.layout.first, container, false);
}else if(currentPosition == 2){
myFragmentView = inflater.inflate(R.layout.second, container, false);
}else if(currentPosition == 3){
myFragmentView = inflater.inflate(R.layout.third, container, false);
}else if(currentPosition == 4){
myFragmentView = inflater.inflate(R.layout.fourth, container, false);
}else if(currentPosition ==5){
myFragmentView = inflater.inflate(R.layout.fifth, container, false);
}else{
myFragmentView = inflater.inflate(R.layout.activity_main, container, false);
}
return myFragmentView;
}
我认为问题出onCreateView
在我无法获得活动标签位置的功能上。
我怎样才能完成这件事。??