We can use setTag() and getTag() to set and get custom objects as per our requirement. The setTag() method takes an argument of type Object, and getTag() returns an Object.
For example,
Person p = new Person();
p.setName("Ramkailash");
p.setId(2000001);
button1.setTag(p);