I have a ListView
and i populated that ListView
with TextView
and Button
using custom adapter.I had generated a click event for that Button
in custom adapter.In that click event i am trying to change the button text and color,up to here its working fine but when i scroll the ListView
up and down the text color of other Button
changing.I had stop here from past couple of days...
Here is some code which i had tried so far
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View v=convertView;
final ViewHolder holder;
if(convertView ==null)
{
convertView = mInlfater.inflate(R.layout.attendancelistview,null);
holder = new ViewHolder();
holder.b1 = (Button)convertView.findViewById(R.id.row3);
holder.tv1 = (TextView)convertView.findViewById(R.id.row1);
holder.tv2 = (TextView)convertView.findViewById(R.id.row2);
convertView.setTag(holder);
}
else
{
holder =(ViewHolder) convertView.getTag();
}
//List<StudentData> data = list.get(position).Rno;
holder.tv1.setText(String.valueOf(list.get(position).Rno));
holder.tv2.setText(list.get(position).StudentName);
holder.b1.setText(list.get(position).Attendance);
holder.b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(holder.b1.getText().equals("Present"))
{
holder.b1.setText("Absent");
//list.get(position).put("Attendance", "Absent");
holder.b1.setTextColor(Color.RED);
}
else if(holder.b1.getText().equals("Absent"))
{
holder.b1.setText("Present");
//list.get(position).put("Attendance", "Present");
holder.b1.setTextColor(Color.GREEN);
}
String rno1= String.valueOf(holder.tv1.getText());
name=String.valueOf(holder.tv2.getText());
}
});
return convertView;
}
static class ViewHolder
{
Button b1;
TextView tv1,tv2,tv3;
}