daimajia / daimajia/AndroidSwipeLayout
swipeLayout.addSwipeListener causing deletion of multiple items in BaseSwipeAdapter
- Dominant language
- Java
- Stars
- 12.3k
- Forks
- 2.6k
- PR merge metrics
- No merged PRs in 30d
Description
I have extended BaseSwipeAdapter and in one similar issue, I read the problem was caused by NOT using setSwipeAdapter and using addSwipeAdapter instead. That function is a part of SwipeLayout and not BaseSwipeAdapter. Another solution was using swipeLayout.removeAllSwipeListeners, which again wasn't available. Also, swipeLayout.close() isn't working either. Now even after using a runnable. Here's the code:
`
class schedulecontactsAdapter extends BaseSwipeAdapter
{
Context context;
View convertView;
private ArrayList schedinfo;
private TextView listemptytext;
private String number = "",name = "",photo = "",time="",date="",dialnumber="";
private long timeinmills;
private ArrayList diffnums;
private static LayoutInflater inflater = null;
schedulecontactsAdapter(Context context, ArrayList schedinfo, TextView listemptytext)
{
// TODO Auto-generated constructor stub
this.context = context;
this.schedinfo=schedinfo;
this.listemptytext=listemptytext;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getSwipeLayoutResourceId(int position)
{
return R.id.swipe;
}
@Override
public View generateView(final int position, final ViewGroup parent)
{
//vi = inflater.inflate(R.layout.row_in_schedulelist,parent,false);
View vi = LayoutInflater.from(context).inflate(R.layout.row_in_schedulelist, parent,false);
return vi;
}
public void fillValues(final int position, View convertView)
{
View vi=convertView;
final SwipeLayout swipeLayout = (SwipeLayout) vi.findViewById(R.id.swipe);
TextView schedinfotextview=(TextView) vi.findViewById(R.id.schedinfotextview);
ImageView schcontactphoto=(ImageView) vi.findViewById(R.id.schlistcontactphotopic);
Bundle b=schedinfo.get(position);
if(b!=null)
{
name = b.getString("name");
diffnums = b.getStringArrayList("numbers");
dialnumber = b.getString("dialnumber");
photo = b.getString("photo");
time = b.getString("time");
date = b.getString("date");
timeinmills = b.getLong("timeinmills");
String temp = "Will call " + name + "\nat " + time + " of " + date + " on\nnumber " + dialnumber;
schedinfotextview.setText(temp);
schcontactphoto.setImageURI(Uri.parse(photo));
}
swipeLayout.addSwipeListener(new SimpleSwipeListener() {
@Override
public void onOpen(SwipeLayout layout)
{
final Bundle temp=schedinfo.get(position);
schedinfo.remove(position);
notifyDataSetChanged();
Snackbar.make(swipeLayout,"Schedule cancelled", Snackbar.LENGTH_INDEFINITE)
.setAction("Undo", new View.OnClickListener()
{
@Override
public void onClick(View v)
{
schedinfo.add(position,temp);
notifyDataSetChanged();
((SwipeLayout)v).close(true);
}
})
.setActionTextColor(Color.YELLOW)
.show();
}
});
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return schedinfo.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return schedinfo.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}
`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.