ambit
ambit

Reputation: 1119

Prevent expandable listview from showing its child during a long swipe

I have implemented two features on my expandable listview.

  1. The child view should be shown when a user clicks on the group view (which happens by default)
  2. Have also implemented a left to right long swipe listener where in if a user does a long swipe , he would be taken to a new activity

Both these actions are working fine. But when I do a long swipe across the screen, the listview opens and shows the child element too (see 1 above) before being taken to a new activity.

Relevant portion of the code is:

    ExpandableListView elvCat;
    .
    .
    .
    mAdapter = new SimpleExpandableListAdapter(
            WordListFragment.this.getActivity(),
            groupDataCat,
            R.layout.word_list_item,
            new String[] {WORD},
            new int[] { R.id.tvWord },
            childDataCat,
            R.layout.meaning_list_item,
            new String[] {MEANING},
            new int[] { R.id.tvMeaning}
    );

    elvCat.setAdapter(mAdapter);
    .
    .

    elvCat.setOnGroupClickListener(new OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView arg0, View arg1, int arg2,
                long arg3) {
            if (swipeDetector.swipeDetected()) {
                if (swipeDetector.getAction() == SwipeDetector.Action.LR) {
                    elvCat.collapseGroup(arg2);
                    Toast.makeText(getActivity(),
                        "Left to right", Toast.LENGTH_SHORT).show();
                }
                if (swipeDetector.getAction() == SwipeDetector.Action.RL) {
                    Intent detailIntent = new Intent(getActivity(), WordDetailActivity.class);
                    startActivity(detailIntent);
                }
            }
            return false;
        }
    });

Please tell me how to avoid this.

Upvotes: 0

Views: 430

Answers (1)

ambit
ambit

Reputation: 1119

I figured out the way to fix this. Overriding ongroupclick() function in the following way does the trick.

@Override
            public boolean onGroupClick(ExpandableListView arg0, View arg1,
                    int arg2, long arg3) {
                if (swipeDetector.swipeDetected()) {
                    if (swipeDetector.getAction() == SwipeDetector.Action.LR) {
                        return true;
                    }
                    if (swipeDetector.getAction() == SwipeDetector.Action.RL) {
                        return true;
                    }
                } else {
                    return false;
                }
                return false;
            }
        });

Upvotes: 1

Related Questions