2017-02-19 6 views
0

FirebaseUI RecyclerView에서 작업 중이며 목록 항목을 클릭 할 때 대화 상자 조각을 만들려고합니다. 새 조각을 만들려면 getFragmentManager()을 정적 클래스에서 호출해야합니다. 오류는 IDE에서 제공됩니다. Firebase 리사이클러 어댑터에 의해 직접 인스턴스화되기 때문에 정적 뷰홀 클래스에 매개 변수를 전달할 수 없습니다.FirebaseUI의 정적 뷰 홀더 클래스에서 getFragmentManager() 메서드 호출

mAdapter = new FirebaseRecyclerAdapter<Course, CourseViewHolder>(
      Course.class, 
      R.layout.list_item_course, 
      CourseViewHolder.class, 
      mDatabaseReference 
    ) { 

정적 클래스 코드가 여기에 있습니다 : :

private static class CourseViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 
     TextView textView; 

    public CourseViewHolder(View itemView) { 
     super(itemView); 
     textView = (TextView) itemView.findViewById(R.id.list_item_course_title_text_view); 

    } 

    @Override 
    public void onClick(View v) { 
     FragmentManager manager = getFragmentManager(); 
     CourseOperationFragment CourseOperationFragment = new CourseOperationFragment(); 
     CourseOperationFragment.show(manager, DIALOG_OPERATION); 
    } 
} 

답변

2

당신은보기에 getContext()를 호출하여보기와 관련된 Context를 얻을 수 있습니다 여기에

는 어댑터의 코드입니다. 그런 다음 해당 컨텍스트가 instanceof FragmentActivity인지 확인합니다. 그럴 경우 ContextFragmentActivity으로 전송하고 여기에서 메소드를 호출하여 조각을 조작 할 수 있습니다.

+0

감사합니다. 꽤 놀랐습니다. – NightOwl

+0

이것은 미친 도움이되었습니다, 감사합니다! 다른 사람들에게 도움이되는 경우 : 각 단편에서 사용자의 답변을 수집하여 일련의 단편으로 활동을 수행 했으므로 사용했습니다. 프래그먼트 중 하나에는 사용자가 목록에서 선택할 Firebase RecyclerView가 있습니다. FirebaseRecyclerAdapter 내부에서 아이템을 선택한 후 호출하는 Activity의 메소드를 호출하여 다음 Fragment로 이동하려고합니다. 이 솔루션은 우아하고 훌륭하게 작동합니다! – Lucy