CheckedTextView onClickListener使展开/折叠按钮无响应

时间:2019-02-18 08:46:03

标签: android expandablelistview checkedtextview

我正在使用ExpandableListAdapter在搜索分类时显示相关项目。我添加了onClickListener,以便当用户单击类别的标题时,它将其发送到相关活动。但是,现在展开/折叠按钮不起作用,onClickListener似乎与它重叠。

相关代码:

从ExpandableListAdapter:

 @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
                         View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.task_group_row, null);
    }
    final TaskGroup taskGroup = (TaskGroup) getGroup(groupPosition);
    CheckedTextView taskListTitleTextView=convertView.findViewById(R.id.task_list_group_title);
    //onClick - go to relevant group's TaskList
    taskListTitleTextView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Create a new intent to view the tasks in the chosen list
            Intent taskIntent = new Intent(activity, TaskActivity.class);

            // Send the intent to launch a new activity
            activity.startActivity(taskIntent);
        }
    });
    ((CheckedTextView) convertView).setText(taskGroup.taskListTitle);
    ((CheckedTextView) convertView).setChecked(isExpanded);
    return convertView;

XML:

<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/task_list_group_title"
    android:layout_width="wrap_content"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:gravity="center"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    android:textAlignment="center"
    android:textSize="20sp"
    android:textStyle="bold" />

0 个答案:

没有答案