未在可展开列表视图中获取组上的按钮单击事件

时间:2014-10-07 13:52:18

标签: android android-fragments expandablelistview

这是组视图的相关XML部分。

 <LinearLayout
            android:id="@+id/downarrowlayout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:orientation="vertical" >

            <Button
                android:id="@+id/downArrowButn"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_gravity="center"
                android:background="@drawable/ic_down_arrow"
                android:focusable="false"
                android:focusableInTouchMode="false" />
        </LinearLayout>

//这是获取组视图,其中已经实现了按钮列表器。

@Override
    public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)
    {
        JSONObject obj = getGroup(groupPosition);
        viewHolder = new ViewHolderGrp();
        if(convertView == null)
        {
            LayoutInflater infalInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.reminders_group_view, null);
            viewHolder.reminderString = (TextView) convertView.findViewById(R.id.reminderString);
            viewHolder.time = (TextView) convertView.findViewById(R.id.time);
            viewHolder.repeat = (TextView) convertView.findViewById(R.id.repeat);
            viewHolder.date = (TextView) convertView.findViewById(R.id.date);
            viewHolder.alarmButton = (ImageButton) convertView.findViewById(R.id.alarmButton);
            convertView.setTag(viewHolder);

        }
        else
        {
            viewHolder = (ViewHolderGrp) convertView.getTag();
        }
        try
        {
            State state = State.valueOf(obj.getInt(EventConstants.STATE));
            viewHolder.reminderString.setText(getReminderString(obj.getString(EventConstants.SHORT_MESSAGE), state));
            viewHolder.time.setText(getStartTime(obj.getInt(EventConstants.START_HOUR), obj.getInt(EventConstants.START_MIN), state));
            viewHolder.repeat.setText(getRepeatString(obj));
            viewHolder.date.setText(getdateString(obj, state));
            LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.alpha);
            if(state == State.ON)
            {
                viewHolder.alarmButton.setBackgroundResource(R.drawable.ic_alarm_on);
                ll.setAlpha((float) 1);
            }
            else
            {
                viewHolder.alarmButton.setBackgroundResource(R.drawable.ic_alarm_off);
                ll.setAlpha((float) 0.5);
            }

        }
        catch(JSONException e)
        {
            e.printStackTrace();
            ErrorReportProvider.sendErrorMail(Helper.getStackTrace(e), ImleePhotoConstant.defaultDisplay);
        }

        viewHolder.alarmButton.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                callUpdateService(groupPosition);
            }
        });

        Button downArrowBtn = (Button) convertView.findViewById(R.id.downArrowButn);

        downArrowBtn.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                onGroupExpanded(groupPosition);
            }
        });

        ExpandableListView expandableListView = (ExpandableListView) parent;
        LinearLayout ll = (LinearLayout) convertView.findViewById(R.id.ListHeader);
        LinearLayout downArrow = (LinearLayout) convertView.findViewById(R.id.downarrowlayout);
        if(expandableListView.isGroupExpanded(groupPosition))
        {
            ll.setBackgroundResource(R.drawable.tp_lft_tp_rgt_bdr_radius);
            downArrow.setVisibility(View.INVISIBLE);
        }
        else
        {
            ll.setBackgroundResource(R.drawable.remind_list_header);
            downArrow.setVisibility(View.VISIBLE);
        }


        return convertView;
    }

在可展开列表视图中未在组上获取按钮点击事件。

我尝试了以下方法

  1. focussability设为false

  2. focussability设置为true,然后为按钮设置点击监听器,然后将focussability设置为false

  3. android:descendantFocusability="blocksDescendants"设为viewgroup

  4. 通过合并尝试选项2和3。

  5. 但以上都没有奏效。请提出解决方案。任何人的早期回复都将受到高度赞赏。

0 个答案:

没有答案