1

나는 안드로이드 응용 프로그램을 개발 중이다. 지금까지는 작동합니다. 한 곳에서 CursorTreeAdapter를 사용하고 있습니다. CursorTreeAdapter에서 그룹에 단추를 추가해야합니다. Textview를 쉽게 추가 할 수 있지만 버튼을 추가하면 목록이 제대로 작동하지 않습니다. 그것은 확장되지 않습니다. 단추를 제대로 추가하려면 어떻게해야합니까? 가능한 경우 몇 가지 코드 예제를 제공 할 수 있습니까? 이 두 함수를 수정하려고했지만 xml gorup 파일에 단추를 추가하면 목록이 확장되지 않습니다.Android 앱에서 CursorTreeAdapter의 모든 그룹에 버튼 (대화 상자 메뉴가 열립니다)을 추가하려면 어떻게해야합니까?

@Override 
    protected void bindGroupView(View view, Context context, Cursor cursor, 
      boolean isExpanded) { 
     TextView text_line1 = (TextView) view 
       .findViewById(R.id.work_list_group_view); 
     text_line1.setText("title1"); 

     TextView text_line2 = (TextView) view 
       .findViewById(R.id.work_list_group_view2); 
     text_line2.setText("title2"); 

     ImageButton button = (ImageButton) view.findViewById(R.id.context_menu_button); 


    } 

    @Override 
    public View newGroupView(Context context, Cursor cursor, 
      boolean isExpanded, ViewGroup parent) { 
     return getLayoutInflater().inflate(
       R.layout.work_list_expandable_group, parent, false); 
    } 

답변

0
protected void bindGroupView(View view, Context context, Cursor cursor, 
          boolean isExpanded) { 
    TextView text_line1 = (TextView) view 
      .findViewById(R.id.work_list_group_view); 
    text_line1.setText("title1"); 

    text_line1.setOnClickListener(new View.OnClickListener() { 
     // Open your dialog here 
    }); 

    TextView text_line2 = (TextView) view 
      .findViewById(R.id.work_list_group_view2); 
    text_line2.setText("title2"); 

    ImageButton button = (ImageButton) view 
       .findViewById(R.id.context_menu_button); 
} 
0
@Override 
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) { 
    TextView text_line1 = (TextView) view.findViewById(R.id.work_list_group_view); 
    text_line1.setText("title1"); 

    TextView text_line2 = (TextView) view.findViewById(R.id.work_list_group_view2); 
    text_line2.setText("title2"); 

    ImageButton button = (ImageButton) view.findViewById(R.id.context_menu_button); 
    // Magic comes here, you should add: 
    button.setFocusable(false); // ListItem is not clickable if it has focusable child's. 
    button.setOnClickListener(new OnClickListener(){ ... }); 

} 

@Override 
public View newGroupView(Context context, Cursor cursor, 
     boolean isExpanded, ViewGroup parent) { 
    return getLayoutInflater().inflate(R.layout.work_list_expandable_group, parent, false); 
}