onCreateView의 기능을 사용하여 동적으로 뷰 변경

rahstame

현재 나는 이런 식으로 처리되는 활동을 연결했습니다 Activity A --> Activity B--Activity C. 중첩 된 조각을 사용할 수 있고 하나의 활동에 포함될 수 있음을 발견했습니다. 그래서 나는 그것이 될 것이라고 상상했습니다.

Main Activity
--Fragment A -> Fragment B -> Fragment C

아래 코드에서 생성 된 모든 조각에 대한 텍스트를 동적으로 채울 수 있습니다. 어떻게 조각을 만들고 위의 흐름을 다른 관점에서 사용할 수 있는지 궁금합니다.

그래서 내 가능한 if statements해결책은 하나의 onCreateView에서 어떤 조각이 표시되는지 확인하는 것입니다. 당신의 생각은 조각의 동적 생성의 복잡한 개념을 이해하는 데 도움이 될 것입니다. 감사

    public class CollectionDemoActivity extends FragmentActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide fragments representing
     * each object in a collection. We use a {@link android.support.v4.app.FragmentStatePagerAdapter}
     * derivative, which will destroy and re-create fragments as needed, saving and restoring their
     * state in the process. This is important to conserve memory and is a best practice when
     * allowing navigation between objects in a potentially large collection.
     */
    DemoCollectionPagerAdapter mDemoCollectionPagerAdapter;

    /**
     * The {@link android.support.v4.view.ViewPager} that will display the object collection.
     */
    ViewPager mViewPager;

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collection_demo);

        // Create an adapter that when requested, will return a fragment representing an object in
        // the collection.
        // 
        // ViewPager and its adapters use support library fragments, so we must use
        // getSupportFragmentManager.
        mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());

        // Set up action bar.
        final ActionBar actionBar = getActionBar();

        // Specify that the Home button should show an "Up" caret, indicating that touching the
        // button will take the user one step up in the application's hierarchy.
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Set up the ViewPager, attaching the adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mDemoCollectionPagerAdapter);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                // This is called when the Home (Up) button is pressed in the action bar.
                // Create a simple intent that starts the hierarchical parent activity and
                // use NavUtils in the Support Package to ensure proper handling of Up.
                Intent upIntent = new Intent(this, MainActivity.class);
                if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
                    // This activity is not part of the application's task, so create a new task
                    // with a synthesized back stack.
                    TaskStackBuilder.from(this)
                            // If there are ancestor activities, they should be added here.
                            .addNextIntent(upIntent)
                            .startActivities();
                    finish();
                } else {
                    // This activity is part of the application's task, so simply
                    // navigate up to the hierarchical parent activity.
                    NavUtils.navigateUpTo(this, upIntent);
                }
                return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A {@link android.support.v4.app.FragmentStatePagerAdapter} that returns a fragment
     * representing an object in the collection.
     */
    public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter {

        public DemoCollectionPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            Fragment fragment = new DemoObjectFragment();
            Bundle args = new Bundle();
            args.putInt(DemoObjectFragment.ARG_OBJECT, i + 1); // Our object is just an integer :-P
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public int getCount() {
            // For this contrived example, we have a 100-object collection.
            return 100;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return "OBJECT " + (position + 1);
        }
    }

    /**
     * A dummy fragment representing a section of the app, but that simply displays dummy text.
     */

    public static class DemoObjectFragment extends Fragment {

        public static final String ARG_OBJECT = "object";

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.load_main_menu_activity, container, false);
            Bundle args = getArguments();
           //((TextView) rootView.findViewById(android.R.id.text1)).setText(
                 //   Integer.toString(args.getInt(ARG_OBJECT)));
            return rootView;
        }
    }
}
닐 레쉬 파텔
public class FirstFragment extends Fragment implements OnClickListener {
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.first_fragment, container, false);
        Button nextButton = (Button) view.findViewById(R.id.button_first);
        nextButton.setOnClickListener(this);
        return view;
    }
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

뷰셀의 크기를 동적으로 변경하는 Xamarin Forms

분류에서Dev

Android-웹뷰 사용자 정의 글꼴을 동적으로 변경

분류에서Dev

vsc 확장의 뷰에서 자식을 동적으로 변경하는 방법

분류에서Dev

UITableViewAutomaticDimension을 사용하여 이미지의 tableViewCell 높이를 동적으로 변경

분류에서Dev

webdriverJS를 사용하여 phantomJS의 뷰포트 크기 변경

분류에서Dev

기능을 사용하여 Onclick 기능으로 웹 페이지의 내용을 어떻게 변경합니까?

분류에서Dev

자바 스크립트를 사용하여 TinyMCE 편집기의 배경을 동적으로 변경

분류에서Dev

onClick을 사용하여 동적으로 Java Script 변경 경로

분류에서Dev

jquery UI를 사용하여 크기 조정 가능한 요소의 핸들을 동적으로 변경하는 방법

분류에서Dev

개별 배열을 사용하여 선택기의 옵션을 동적으로 변경

분류에서Dev

차트 색상을 사용하여 도구 설명의 배경색을 동적으로 변경

분류에서Dev

사용자의 뷰 변경을 기반으로 모델을 업데이트하고 있습니까?

분류에서Dev

선택기의 내용을 동적으로 변경

분류에서Dev

스피너를 사용하여 텍스트 뷰의 색상을 동적으로 설정 하시겠습니까?

분류에서Dev

querySelectorAll을 사용하여 입력 값을 동적으로 변경

분류에서Dev

앵커 태그 각도를 사용하여 div의 내용을 동적으로 변경

분류에서Dev

Jquery / Javascript를 사용하여 팝 오버의 데이터 내용을 동적으로 변경

분류에서Dev

PHP if 문을 사용하여 동적으로 링크 변경

분류에서Dev

입력 텍스트 필드를 사용하여 Javascript로 함수의 값을 동적으로 변경

분류에서Dev

jquery를 사용하여 CSS의 속성을 동적으로 변경하는 방법

분류에서Dev

jquery를 사용하여 CSS의 속성을 동적으로 변경하는 방법

분류에서Dev

htmleditor의 배경색을 동적으로 변경하는 방법

분류에서Dev

셸 실행 파일을 사용하여 Lambda 계층의 버전 번호를 동적으로 변경

분류에서Dev

JS / jQuery를 사용하여 인라인 텍스트의 CSS 색상을 동적으로 변경

분류에서Dev

지시문 Angular JS를 사용하여 텍스트의 색상을 동적으로 변경

분류에서Dev

jsp를 사용하여 이전 페이지 입력을 기반으로 웹 페이지의 내용을 동적으로 변경할 수 있습니까?

분류에서Dev

바꾸기 기능을 사용하여 R의 값 변경

분류에서Dev

다른 클래스에서 뷰 배경색을 동적으로 변경하는 방법

분류에서Dev

방향 변경시 어댑터에서 동적으로 생성 된 뷰의 체크 항목을 유지하는 방법

Related 관련 기사

  1. 1

    뷰셀의 크기를 동적으로 변경하는 Xamarin Forms

  2. 2

    Android-웹뷰 사용자 정의 글꼴을 동적으로 변경

  3. 3

    vsc 확장의 뷰에서 자식을 동적으로 변경하는 방법

  4. 4

    UITableViewAutomaticDimension을 사용하여 이미지의 tableViewCell 높이를 동적으로 변경

  5. 5

    webdriverJS를 사용하여 phantomJS의 뷰포트 크기 변경

  6. 6

    기능을 사용하여 Onclick 기능으로 웹 페이지의 내용을 어떻게 변경합니까?

  7. 7

    자바 스크립트를 사용하여 TinyMCE 편집기의 배경을 동적으로 변경

  8. 8

    onClick을 사용하여 동적으로 Java Script 변경 경로

  9. 9

    jquery UI를 사용하여 크기 조정 가능한 요소의 핸들을 동적으로 변경하는 방법

  10. 10

    개별 배열을 사용하여 선택기의 옵션을 동적으로 변경

  11. 11

    차트 색상을 사용하여 도구 설명의 배경색을 동적으로 변경

  12. 12

    사용자의 뷰 변경을 기반으로 모델을 업데이트하고 있습니까?

  13. 13

    선택기의 내용을 동적으로 변경

  14. 14

    스피너를 사용하여 텍스트 뷰의 색상을 동적으로 설정 하시겠습니까?

  15. 15

    querySelectorAll을 사용하여 입력 값을 동적으로 변경

  16. 16

    앵커 태그 각도를 사용하여 div의 내용을 동적으로 변경

  17. 17

    Jquery / Javascript를 사용하여 팝 오버의 데이터 내용을 동적으로 변경

  18. 18

    PHP if 문을 사용하여 동적으로 링크 변경

  19. 19

    입력 텍스트 필드를 사용하여 Javascript로 함수의 값을 동적으로 변경

  20. 20

    jquery를 사용하여 CSS의 속성을 동적으로 변경하는 방법

  21. 21

    jquery를 사용하여 CSS의 속성을 동적으로 변경하는 방법

  22. 22

    htmleditor의 배경색을 동적으로 변경하는 방법

  23. 23

    셸 실행 파일을 사용하여 Lambda 계층의 버전 번호를 동적으로 변경

  24. 24

    JS / jQuery를 사용하여 인라인 텍스트의 CSS 색상을 동적으로 변경

  25. 25

    지시문 Angular JS를 사용하여 텍스트의 색상을 동적으로 변경

  26. 26

    jsp를 사용하여 이전 페이지 입력을 기반으로 웹 페이지의 내용을 동적으로 변경할 수 있습니까?

  27. 27

    바꾸기 기능을 사용하여 R의 값 변경

  28. 28

    다른 클래스에서 뷰 배경색을 동적으로 변경하는 방법

  29. 29

    방향 변경시 어댑터에서 동적으로 생성 된 뷰의 체크 항목을 유지하는 방법

뜨겁다태그

보관