I have created a Custom Adapter for a ListView and each element in the listview has 1 TextView and 1 Button
ListView
[TextView 1] [Button 1]
[TextView 2] [Button 2]
..(so on)
My requirement: You are allowed to click button only once. It's like 'Like' button.After the first click, isClickable only for the button in that row should be set to false.
Mycode:
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View row=convertView;
ViewHolder holder=null;
if(row==null)
{
row=msgInflator.inflate(R.layout.row,parent,false);
holder = new ViewHolder(row);
holder.msg=(TextView)row.findViewById(R.id.message_text);
holder.up=(Button)row.findViewById(R.id.upVote);
holder.up.setTag(holder);
holder.up.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ViewHolder hold=(ViewHolder)v.getTag();
hold.up.setClickable(false);
}
});
row.setTag(holder);
}
else
{
holder=(ViewHolder)row.getTag();
}
holder.msg.setText(messages.get(position).getMessage());
holder.up.setText(messages.get(position).getUp());
return row;
}
Problem:
When i click on Button 1:
Button 1 isClickable set to false -> which is required
Few other Buttons (ex: Button 5,6) isClickable is also set to false -> Which is undesired
How can i achieve my required output?