You should get the view
with the onClick
method as follows:
holder.btnAdd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(scale);
}
});
You pass the View v
parameter in your onClick
method. Then, your method is attached to the View which is in your case: holder.btnAdd
, therefore v == holder.btnAdd
Update
It's a bit stupid what I did to resolve this. This is really easy, indeed you initialize viewHolder
as null
but you shouldn't. That's why you can't make your viewHolder
as final
:
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
final ViewHolder holder; // without initialized
if(vi == null){
vi = inflater.inflate(R.layout.list_row, null);
holder = new ViewHolder();
holder.tvName = (TextView)vi.findViewvById(R.id.name);
holder.tvDescription = (TextView)vi.findViewvById(R.id.desc);
holder.btAdd = (Button)vi.findViewvById(R.id.btnadd);
}else{
holder = (ViewHolder) vi.getTag();
}
holder.btnAdd.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(scale);
holder.tvName.setVisibility(View.GONE);
}
});
return vi;
}
That's it!