0
좋아요. 그래서 조각 A가있는 액티비티 A와 프래그먼트 B가있는 액티비티 B가 있습니다. 액티비티 A는 로그인 화면과 같은 기본 화면입니다. 이제 조각 B에서 일부 작업을 시도하고 만료 된 세션이있을 때 메시지를 보내고 로그 아웃하고 기본 화면으로 돌아갑니다.여러 액티비티에서 프래그먼트의 인터페이스 구현
이제 조각 B는 통신에 사용되는 인터페이스를 가지고 있습니다 다른 여러 기능을위한 활동 B. 내 활동 A가이 로그 아웃 세션을 위해 단편 B의 동일한 인터페이스를 구현해야합니까, 아니면 더 좋은 방법이 있습니까?
그림 :
public class fragmentB extends Fragment {
public interface FragmentBProgressListener {
public void onShowDataDialog();
public void onRemoveData();
public void onSessionError(String errordata);
}
//or should i have another interface that implements this only in activity A
}
활동 B :
public class ActivityB extends Activity implements FragmentBProgressListener {
public void onShowDataDialog(){
}
public void onRemoveData(){
}
public void onSessionError(String errordata){
// finish Activity here
}
}
활동 A :
public class ActivityA extends Activity implements FragmentAListener, FragmentBFragmentBProgressListener {
public void onFragA(){
}
public void onShowDataDialog(){
}
public void onRemoveData(){
}
public void onSessionError(String errordata){
// show error dialog here from fragment B
}
}
이 좋은 방법입니다? 내가 알아야 할 모든 함정들?
나는 그 일을 생각하고 있었지만 onAttach()에서 여러 청취자를 활동에 추가하는 방법을 모르겠습니다. – irobotxxx
@ sparrow : 당신이 무슨 말을하고 있는지 전혀 모르겠습니다. 프래그먼트가 호스팅 활동에서 메소드를 호출하기를 원하면'getActivity()'를 호출하고 결과를 적절한 인터페이스로 캐스팅 한 다음 해당 인터페이스에서 메소드를 호출한다. – CommonsWare
나는 당신이 당신의 대답으로 제안한 것처럼한다면 A 액티비티에서 다른 인터페이스를 구현해야만한다는 것을 의미했다. 그래서 나는 이것을 조각 B의 onAttach()에 어떻게 첨부해야 하나? – irobotxxx