2017-05-08 1 views
0

사용자 지정 어댑터에서로드 된 대화 상자 조각 내에서 목록을 호출하고 있습니다.대화 상자 단편 java.lang.IllegalStateException : 지정된 하위에 이미 상위가 있습니다. 먼저 부모의 부모에 대해 removeView()를 호출해야합니다.

내 조각로드

ProfileListViewHolder.imageButtonMore.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      ProfileDialog ProfileDialogFragment = new ProfileDialog(); 

      ProfileDialogFragment.setStyle(DialogFragment.STYLE_NORMAL, R.style.CustomDialog); 
      android.support.v4.app.FragmentTransaction fragmentManager =((AppCompatActivity)context).getSupportFragmentManager().beginTransaction(); 

      fragmentManager.replace(R.id.drawer_layout,ProfileDialogFragment) .addToBackStack(null).commit(); 

     } 
    }); 

이 내가 당신 대신 profileView의 profileListView을 반환하는

public class ProfileDialog extends android.support.v4.app.DialogFragment { 

private Context context; 

public View profileView; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 


public void setTitle(String title) { 
    Dialog dialog = getDialog(); 
    dialog.setTitle(title); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    if (profileView == null) { 
      profileView = inflater.inflate(R.layout.fragment_profile_dialog, container,false); 
    } else { 
     ((ViewGroup) profileView .getParent()).removeView(profileView); 
    } 

    ListView profileListView = (ListView) profileView.findViewById(R.id.lstvSelectedProfile); 


    return profileListView; 
} 

@Override 
public void onStart() { 
    super.onStart(); 
    //addInnerFragment(); 
} 

@Override 
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 
    super.onViewCreated(view, savedInstanceState); 


} 
@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
    Dialog dialog = super.onCreateDialog(savedInstanceState); 
    return dialog; 
} 

} 
+1

시도,이 같은 코드를 변경'((뷰 그룹) profileView.getParent()). removeView (profileView)'? – azizbekian

+0

@azizbekian : 여기에서 문제가 될 수있는 부모를 제거하는 데 도움이 될 것이라고 생각했습니다. –

+0

'ProfileDialog'를 대화 상자로 사용하려면, 트랜잭션이 아닌'show()'메소드를 사용해야합니다 거기서 사용. –

답변

0

을 사용하고 내 대화입니다.

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     profileView = inflater.inflate(R.layout.fragment_profile_dialog, container, false); 
     ListView profileListView = (ListView) profileView.findViewById(R.id.lstvSelectedProfile); 
     return profileView; 
    } 
0

는의 목적은 무엇입니까

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 

    profileView = inflater.inflate(R.layout.fragment_profile_dialog, container,false); 

    ListView profileListView = (ListView) profileView.findViewById(R.id.lstvSelectedProfile); 

    return profileView; 
} 
+0

Krish의 답변과 다른 점은 무엇입니까? –

관련 문제