2

我想在我的片段中制作一个垂直侧视图寻呼机

我试过这样,但我不知道如何将视图传递回女性类表单TestFragment 类

这是我的主要课程

public class women extends Fragment
{

@Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstance)
    {

         startActivity(new Intent(getActivity(), women_activity.class));

                 return null;
}





public class women_activity extends FragmentActivity{

    View view;
    @SuppressLint("ShowToast")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.frgment_1);

        //Set up the pager
        DirectionalViewPager pager = (DirectionalViewPager)findViewById(R.id.pager);
        pager.setAdapter(new TestFragmentAdapter(getSupportFragmentManager()));
        pager.setOrientation(DirectionalViewPager.VERTICAL);

    }

}

TestFragmentAdapter 类

public class TestFragmentAdapter extends FragmentPagerAdapter {

protected static final String[] CONTENT = new String[] { "This", "Is Is", "A A A", "Test", };

public TestFragmentAdapter(FragmentManager fm) {
    super(fm);
    // TODO Auto-generated constructor stub
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return CONTENT.length;
}

@Override
public Fragment getItem(int position) {
    // TODO Auto-generated method stub
    return TestFragment.newInstance(CONTENT[position]);
}

}

测试片段类

 public class TestFragment extends Fragment{
    View mView,layout ;
    ViewPager mViewPager;
    private String mContent="????";
    private static final String KEY_CONTENT = "TestFragment:Content";
    @SuppressWarnings("deprecation")
    @Override
    public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState)
    {
        //mView = inflater.inflate(R.layout.frgment_1, container,false);
        if ((savedInstanceState != null) && savedInstanceState.containsKey(KEY_CONTENT)) {
            mContent = savedInstanceState.getString(KEY_CONTENT);
        }




            TextView text = new TextView(getActivity());
            text.setText(mContent);
            text.setTextSize(20 * getResources().getDisplayMetrics().density);
            text.setPadding(20, 20, 20, 20);
            text.setGravity(Gravity.CENTER);

            LinearLayout layout = new LinearLayout(getActivity());
            layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            layout.setGravity(Gravity.CENTER);
            layout.addView(text);

            return layout;
        }

        public static TestFragment newInstance(String content) {
            TestFragment fragment = new TestFragment();

            StringBuilder builder = new StringBuilder();
            for (int i = 0; i < 30; i++) {
                builder.append(content).append(" ");
            }
            builder.deleteCharAt(builder.length() - 1);
            fragment.mContent = builder.toString();

            return fragment;
        }
4

0 回答 0