В приложении для Android, как я могу добавить кнопку (она откроет диалоговое меню) для каждой группы в CursorTreeAdapter? - PullRequest
1 голос
/ 01 марта 2012

Я занимаюсь разработкой приложения для Android. Пока это работает. Я использую CursorTreeAdapter в одном месте. Мне нужно добавить кнопку в группы в CursorTreeAdapter. Я могу легко добавить текстовое представление, но когда я добавляю кнопку, мой список не работает. Это не расширяется. Как правильно добавить кнопку? Если это возможно, можете ли вы привести примеры кода? Я попытался сделать это, чтобы изменить эти две функции, но когда я добавляю кнопку в файл xml gorup, список не расширяется

@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);
    }

Ответы [ 2 ]

0 голосов
/ 12 июня 2013
@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);
}
0 голосов
/ 29 июня 2012
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);
}
...