在Android应用程序中,如何向CursorTreeAdapter中的每个组添加按钮(它将打开对话框菜单)?

我正在开发一个android应用程序。到目前为止它的工作。我在一个地方使用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);

}

回答:

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

}

回答:

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

}

以上是 在Android应用程序中,如何向CursorTreeAdapter中的每个组添加按钮(它将打开对话框菜单)? 的全部内容, 来源链接: utcz.com/qa/262806.html

回到顶部