마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

뷰페이저 내 프래그먼트로 돌아왔을 때 자동으로 갱신하기

0 추천

안녕하세요. 첨부이미지와 같은 화면을 구성중입니다.

중간에 보이는 네모 버튼이 동적으로 바뀌는 구조인데, 스크롤 했을 때 버튼을 바꾸는 건 가능한데

 

버튼 클릭 -> 새 액티비티 실행 -> 새 액티비티 종료 -> 뷰페이저로 돌아옴

 

이 과정에서 어떻게 프래그먼트내 버튼을 새로 고침해야되는지 잘 모르겠습니다. 해당 버튼을 갱신하는 함수는 해당 프래그먼트의 메소드로 구현되어 있습니다.

public void setButtonText() {
    Calendar calendar = Calendar.getInstance();
    SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");
    String values[] = {dataFormat.format(calendar.getTime())};
    Cursor cursor = db.rawQuery("select * from word_group where next_test_date = ?",values);
    String textOfButton;
    if (cursor.getCount() != 0)
    {
        cursor.moveToNext();
        dataFormat = new SimpleDateFormat("yy MM dd");
        String testDate = dataFormat.format(calendar.getTime());
        textOfButton = testDate + " 시험\n" + "클릭해서 시험 시작";
        testWordButton.setText(textOfButton);
    }
    else
    {
        textOfButton = "오늘 볼 시험이 없습니다";
        testWordButton.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
        testWordButton.setText(textOfButton);
    }

}
익명사용자 님이 2018년 8월 31일 질문

1개의 답변

+1 추천
fragment 내의 onResume에서 갱신하시거나,

새 액티비티를 startActivityForResult로 실행해서 fragment 내의 onActivityResult에서 갱신하시면 될것같네요
버닝 (4,880 포인트) 님이 2018년 9월 1일 답변
onResume에서 하면 됬었네요!
ForResult도 까먹고 있었는데 이기회에 다시 복습하게 됬습니다 감사합니다.
...