daimajia / daimajia/AndroidSwipeLayout

List item swipe layout staying visible on next item if current list item is removed. Can't delete list item with smooth hide animation..

Open
#279 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Hello,

I faced with problem to close(to hide) swipe content on list items on the other index than 0. I tried to do everything exactly as is mentioned in the docs, but without the luck.

I posting animated gif with problem.

![Problem desc](https://media.giphy.com/media/l2JJI8MyzO504Ll6M/giphy.gif)

Code of the adapter is following:

How can i solve it please? From the docs it is not clear.

Many thanks for any advice.

```
public class MealAdapter extends BaseSwipeAdapter {

private List filteredData;
private static Activity context;
private SwipeLayout mSwipeLayout;

private class ViewHolder {
public ImageView deleteItemIv;
public ImageView countryIconFlag;
public TextView countryNameTv;
public LinearLayout bottomWrapperLayout;
}

public ParticipantGiftAdapter(List listItems, Activity context) {
this.filteredData = listItems;
this.context = context;
}

@Override
public int getCount() {
return filteredData.size();
}

@Override
public Participiant getItem(int position) {
Logger.d("getItem");
return filteredData.get(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public int getSwipeLayoutResourceId(int position) {
Logger.d("getSwipeLayoutResourceId");
return R.id.swipe;
}

@Override
public View generateView(int position, ViewGroup parent) {
Logger.d("generateView");
View viewToReturn = null;
try {
LayoutInflater layoutInflater = context.getLayoutInflater();
viewToReturn = layoutInflater.inflate(R.layout.list_item_participiant, parent, false);
mSwipeLayout = (SwipeLayout) context.findViewById(R.id.swipe);
} catch (Exception e) {
Logger.e(e.getMessage());
}
return viewToReturn;
}

@Override
public void fillValues(int position, View convertView) {
Logger.d("fillValues");
try {
Logger.d("Position :" + position);

ViewHolder holder;
holder = new ViewHolder();

holder.countryNameTv = (TextView) convertView.findViewById(R.id.li_participiant_country_name_tv);
holder.countryIconFlag = (ImageView) convertView.findViewById(R.id.li_participiant_country_flag_iv);
holder.deleteItemIv = (ImageView) convertView.findViewById(R.id.li_participiant_remove_iv);
holder.bottomWrapperLayout = (LinearLayout) convertView.findViewById(R.id.bottom_wrapper);
holder.bottomWrapperLayout.setOnClickListener(mdeleteParticipantClickListener);

// Set ID of the list item
holder.bottomWrapperLayout.setTag(position);

// SET VALUES
Participiant participant = getItem(position);
String caption = participant.getCaption();
if (caption == null) {
caption = context.getString(R.string.select_country);
}

// GET FLAG
Drawable d = null;
if (participant.getCountryCode() == Constants.Global.FLAG_TYPE_DEFAULT) {
d = ContextCompat.getDrawable(context, R.drawable.flag_default);
} else {
d = CommonHelper.getFlagDrawable(participant.getCountryCode(), context, Constants.Global.FLAG_TYPE_GLOBE);
}

holder.countryNameTv.setText(caption);
holder.countryIconFlag.setImageDrawable(d);

registerSwipeListener();
} catch (Exception e) {
Logger.e(e.getMessage());
}
}

private void registerSwipeListener() {
//set show mode.
mSwipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
//add drag edge.(If the BottomView has 'layout_gravity' attribute, this line is unnecessary)
mSwipeLayout.addDrag(SwipeLayout.DragEdge.Left, context.findViewById(R.id.bottom_wrapper));
mSwipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
@Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
Logger.d("onClose");
}

@Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
Logger.d("onUpdate");

}

@Override
public void onStartOpen(SwipeLayout layout) {
Logger.d("onStartOpen");
}

@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
Logger.d("onOpen");
/*
Integer listItemPosition = (Integer) layout.getTag();
ToastHelper.showToast(listItemPosition, 1000, context);
Logger.d("Swiped on item no: " + listItemPosition);
*/
}

@Override
public void onStartClose(SwipeLayout layout) {
Logger.d("onStartClose");
}

@Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
Logger.d("onHandRelease");
}
});
}

private ImageView.OnClickListener mdeleteParticipantClickListener = new ImageView.OnClickListener() {
@Override
public void onClick(View v) {
try {
Integer listItemPosition = (Integer) v.getTag();
String selectedParticipantId = getItem(listItemPosition).getId();
Integer filteredDataSize = filteredData.size();

Logger.d("CLICKED ON ITEM NO: " + listItemPosition);
Logger.d("SELECTEDPARTICIPANT ID: " + selectedParticipantId);
Logger.d("FILTEREDDATA SIZE: " + filteredDataSize);

if (selectedParticipantId == null) {
Logger.d("WANT TO DELETE ITEM ON POSITION " + listItemPosition);
//filteredData.remove(listItemPosition);
filteredData.remove(filteredData.get(listItemPosition));
notifyDataSetChanged();
GiftActivity.updateHeadingLimitValues();
mSwipeLayout.close();
} else {
for (int i = 0; i < filteredDataSize; i++) {
Participiant participantItemFromLv = filteredData.get(i);
Logger.d("Actual participant " + participantItemFromLv.getId());
Logger.d("Selected participant " + selectedParticipantId);
if (participantItemFromLv.getId().equals(selectedParticipantId)) {
Logger.d("Match on the position " + i);
filteredData.remove(participantItemFromLv);
Logger.d("Array now contains " + filteredData.size() + " items");
notifyDataSetChanged();
GiftActivity.removeParticipantFromGiftLimitListView(context, participantItemFromLv);
mSwipeLayout.close();
return;
}
}
}
} catch (Exception e) {
Logger.e(e.getMessage());
}
}
};

}

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.