나는 Activity를 통해 DialogFragment를 가지고있다. 이 DialogFragment는 웹 서비스 호출에 의해 채워지는 listview입니다. 이 목록보기에서 행을 클릭하면 대화 상자가 사라지고 '조각 인터페이스 패턴'을 통해 어댑터에서 전달 된 문자열로 활동이 재개됩니다.어댑터에서 DialogFragment를 닫으려면 어떻게합니까?
public class MyAdapter extends ArrayAdapter<Profile> implements AdapterView.OnItemClickListener {
....
// Activity implements this interface to use callback and get id value
public interface MyDialogListener {
void onFinishMyDialog(String id);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Profile selectedProfile = getItem(position);
String selectedProfileID = selectedProfile.getId();
// fragments dont have their own context, get Activity fragment belongs to
Context context = getContext();
MyDialogListener listener = (MyDialogListener)context;
listener.onFinishMyDialog(selectedProfileID);
/* NO ACCESS TO FRAGMENT, CANNOT DO THIS
dismiss(); */
}
가 어떻게 대화 조각을 취소하고 제어가 다시 활동에 갈 수 있습니다 : 나는 다음과 같은 어댑터 클래스가? 그들은 정적 인 (Android - Getting context of a fragment in a pager)
정적 개체의 사용을 제안하지 마십시오. 활동이 파괴 될 때마다 위험합니다. –