daimajia / daimajia/AndroidSwipeLayout

Cannot update a listener added on a swipeLayout

Open
#334 1 comment 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

When you use swipeLayout.addSwipeListener in a viewHolder pattern, the swipeLayout will save a new swipeListener in an array, and use that one later on. The problem is that the any param that goes with the listener stays the same and cannot be updated later.

My code:

```

@Override
public void fillValues(final int position, final View convertView) {

final ViewHolder holder;
if(convertView.getTag() == null){
MainActivity.trace("holder initiated");
holder = new ViewHolder();

holder.swipeLayout = (SwipeLayout) convertView.findViewById(getSwipeLayoutResourceId(position));
holder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
holder.tvContactName = (TextView) convertView.findViewById(R.id.tv_contact_name);
holder.tvContactNumber = (TextView) convertView.findViewById(R.id.tv_contact_number);
holder.tvContactOrganization = (TextView) convertView.findViewById(R.id.tv_contact_organization);
holder.btnEdit = (ImageView) convertView.findViewById(R.id.btn_edit_contact);
holder.btnDelete = (ImageView) convertView.findViewById(R.id.btn_delete_contact);

convertView.setTag(holder);
}else{
MainActivity.trace("holder recycled");
holder = (ViewHolder) convertView.getTag();
}

//could use here a holder.swipeLayout.clearSwipeListeners() method;
holder.swipeLayout.addSwipeListener(new SimpleSwipeListener(){
@Override
public void onOpen(SwipeLayout layout) {
if(getOpenItems().size() > 0){
closeAllExcept(layout);
}
if(layout.getDragEdge().equals(SwipeLayout.DragEdge.Left)) {

if(!isAlreadyCalling) {
isAlreadyCalling = true;
((TextView) convertView.findViewById(R.id.tv_swipe_call_label))
.setText(mCaller.startCall(
getItem(position).getDefaultPhoneNumber()));

MainActivity.trace(holder.swipeLayout +" apeleaza " + position);
}
}
}
});

Contact contact = getItem(position);

holder.tvContactName.setText(String.format("%s %s", contact.getFirstName(), contact.getLastName()));
holder.tvContactNumber.setVisibility(contact.getDefaultPhoneNumber() != null ? View.VISIBLE : View.GONE);
if(contact.getDefaultPhoneNumber() != null){
holder.tvContactNumber.setText(contact.getDefaultPhoneNumber().getNumber());
}
holder.tvContactOrganization.setVisibility(contact.getOrganizationName() != null ? View.VISIBLE : View.GONE);
if(contact.getOrganizationName() != null){
holder.tvContactOrganization.setText(contact.getOrganizationName());
}

OnClickSwipeListButton onClickListener = new OnClickSwipeListButton(position);
holder.btnEdit.setOnClickListener(onClickListener);
holder.btnDelete.setOnClickListener(onClickListener);

}
```

Am I missing something? Is there a way to do this that I don't know of?

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.