도움이 되었습니까?

해결책

나는 나를 위해 일하는 간단한 해결책을 발견했다.내가 한 일이 여기있다.

testFragment.class

      public static TestFragment newInstance(String content) {
        TestFragment fragment = new TestFragment();
//
//        StringBuilder builder = new StringBuilder();
//        for (int i = 0; i < 20; i++) {
//            builder.append(content).append(" ");
//        }
//        builder.deleteCharAt(builder.length() - 1);
        fragment.mContent = content;

        return fragment;
    }
.

여기에서의 루프를 주석 처리합니다.우리가 플래그로 사용할 mcontent 을 얻으십시오.

이제 onCreateView()에서 다음과 같이 변경합니다.

   @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        TextView text = new TextView(getActivity());
//        text.setGravity(Gravity.CENTER);
//        text.setText(mContent);
//        text.setTextSize(20 * getResources().getDisplayMetrics().density);
//        text.setPadding(20, 20, 20, 20);
//
//        LinearLayout layout = new LinearLayout(getActivity());
//        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
//        layout.setGravity(Gravity.CENTER);
//        layout.addView(text);
        Log.i("mContent",mContent);
        View view=null;
        if(mContent.equalsIgnoreCase("title1"))
        {
            view = inflater.inflate(R.layout.one, container, false);

        }
        else if(mContent.equalsIgnoreCase("title2"))
        {
            view = inflater.inflate(R.layout.two, container, false);
        }
        else if(mContent.equalsIgnoreCase("title3"))
        {
            view = inflater.inflate(R.layout.three, container, false);
        }
        return view;

    }
.

그것은 모두가 필요합니다.이제 플래그로 사용한 제목 이름을 기반으로 뷰를 팽창시킬 수 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top