使用veiwpager和Fragment返回null

时间:2018-05-23 07:20:06

标签: java android android-fragments android-viewpager

我想使用ViewPager但我收到错误。片段返回null。 这段代码有什么问题吗?

public class FirstFragment extends Fragment {

    private Bundle arguments;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.first_fragment, container, false);
        TextView tv = (TextView) v.findViewById(R.id.tvFragFirst);
        tv.setText(getArguments().getString("msg"));
        return v;
    }

    public static FirstFragment newInstance(String text) {

        FirstFragment f = new FirstFragment();
        Bundle b = new Bundle();
        b.putString("msg", text);

        f.setArguments(b);

        return f;
    }

    public void setArguments(Bundle arguments) {
        this.arguments = arguments;
    }
}

0 个答案:

没有答案