본문 바로가기
Front-end/Android (안드로이드 앱 개발)

Android studio(안드로이드 스튜디오) Fragment 플래그먼트와 버튼 적용

by javapp 자바앱 2020. 2. 24.
728x90

 

 

 

button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
   
@Override
   
public void onClick(View v) {
        FragmentTransaction fragmentTransactionClick =
fragmentManager.beginTransaction(); //클릭 함수 내에서 따로 실행
       
if (flag == false) {
           
flag = true;
            fragmentTransactionClick.replace(R.id.
container, new FragmentTwo());
           
//(int containerViewId, Fragment)
           
fragmentTransactionClick.commit();
        }
else if (flag == true) {
           
flag = false;
            fragmentTransactionClick.replace(R.id.
container, new FragmentOne());
           
//(int containerViewId, Fragment)
           
fragmentTransactionClick.commit();
        }
    }
});

댓글