Created
July 13, 2016 04:46
-
-
Save lidemin/0506aa44599fc44ef7d477abb3d377e5 to your computer and use it in GitHub Desktop.
AS's live template for custom recyclerview adapter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class $objectclass$Adapter extends RecyclerView.Adapter<$objectclass$ViewHolder>{ | |
List<$objectclass$> objList; | |
private Context context; | |
private LayoutInflater inflater; | |
public $objectclass$Adapter(Context context) { | |
this.context = context; | |
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); | |
} | |
@Override | |
public $objectclass$ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View view = inflater.inflate(R.layout.$itemlayoutres$, parent, false); | |
return new $objectclass$ViewHolder(view); | |
} | |
@Override | |
public void onBindViewHolder($objectclass$ViewHolder holder, int position) { | |
holder.setData(getItem(position)); | |
} | |
@Override | |
public int getItemCount() { | |
return objList == null ? 0 : objList.size(); | |
} | |
public $objectclass$ getItem(int pos) { | |
return objList.get(pos); | |
} | |
public void addAll(List<$objectclass$> objsAppend) { | |
if (objsAppend == null || objsAppend.size() <= 0) { | |
return; | |
} | |
if (objList == null) { | |
objList = new ArrayList<>(); | |
} | |
objList.addAll(objsAppend); | |
notifyDataSetChanged(); | |
} | |
} | |
public class $objectclass$ViewHolder extends RecyclerView.ViewHolder { | |
public $objectclass$ViewHolder(View itemView) { | |
super(itemView); | |
ButterKnife.bind(this, itemView); | |
} | |
public void setData($objectclass$ obj) { | |
//todo | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment