What is the main purpose of setTag() getTag() methods of View?

Let’s say you generate a bunch of views that are similar. You could set an OnClickListener for each view individually: button1.setOnClickListener(new OnClickListener … ); button2.setOnClickListener(new OnClickListener … ); … Then you have to create a unique onClick method for each view even if they do the similar things, like: public void onClick(View v) { doAction(1); … Read more

Is there an addHeaderView equivalent for RecyclerView?

There isn’t an easy way like listview.addHeaderView() but you can achieve this by adding a type to your adapter for header. Here is an example public class HeaderAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final int TYPE_HEADER = 0; private static final int TYPE_ITEM = 1; String[] data; public HeaderAdapter(String[] data) { this.data = data; } … Read more