-
Notifications
You must be signed in to change notification settings - Fork 2.7k
SwipeAdapter
SwipeAdater
is a helper class to save your time. It can help you to save and restore SwipeLayout
status (OPEN | CLOSE) in ListView
, GridView
etc.
As you know when you want to use ListView
, GridView
, you need an Adapter
to provide data for ListView
, GridView
.
While, there is a problem. How to restore the SwipeLayout
status (OPEN | CLOSE) when user scolling ? For making SwipeLayout
more convinient, I made SwipeAdapter
.
Remember:
-
SwipeAdapter
is extended fromBaseAdapter
.
However, it's a little bit diffirent from BaseAdapter
. You don't need to override getView()
method, there are 3 new methods you need to override.
//return the `SwipeLayout` resource id in your listview | gridview item layout.
public abstract int getSwipeLayoutResourceId(int position);
//render a new item layout.
public abstract View generateView(int position, ViewGroup parent);
/*fill values to your item layout returned from `generateView`.
The position param here is passed from the BaseAdapter's 'getView()*/
public abstract void fillValues(int position, View convertView);
The SwipeAdapter
will automatically maintain the convertView
. You can check out the source code to have a deeper understanding.
ATTENTION: Never bind listeners or fill values in
generateView
. Just generate the view and do everything else infillValues
(e.g using your holder class) See issues #14 and #17
public class GridViewAdapter extends SwipeAdapter {
private Context mContext;
public GridViewAdapter(Context mContext) {
this.mContext = mContext;
}
@Override
public int getSwipeLayoutResourceId(int position) {
return R.id.swipe;
}
//ATTENTION: Never bind listener or fill values in generateView.
// You have to do that in fillValues method.
@Override
public View generateView(int position, ViewGroup parent) {
return LayoutInflater.from(mContext).inflate(R.layout.grid_item, null);
}
@Override
public void fillValues(int position, View convertView) {
TextView t = (TextView)convertView.findViewById(R.id.position);
t.setText((position + 1 )+".");
}
@Override
public int getCount() {
return 50;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
}
Well done! You just finished the entire tutorial of SwipeLayout
!
Now, enjoy it!