I have a ListView
. I am displaying a list of Button
s in it with 3 of them in each row. I can react to the clicks on the Button
s just fine, but now I need to change the text of a Button
from "Apply" to "Applied" after clicking on it.
I have implemented this in the OnClickListener
but now when I click on the Button
it doesn't just set the text of the Button
I clicked on, it also changes the text of other Button
s. I have no idea what's wrong.
This is my Adapter
:
public class InteractiveFederalArrayAdapter extends
ArrayAdapter<FederalProperties> {
Activity context;
List<FederalProperties> list;
public InteractiveFederalArrayAdapter(Activity context,
List<FederalProperties> list) {
super(context, R.layout.federal_row, list);
// TODO Auto-generated constructor stub
this.context = context;
this.list = list;
}
static class ViewHolder {
protected TextView titleView;
protected TextView subTitleView;
protected Button phoneButton;
protected Button emailButton;
protected Button infoButton;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.federal_row, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.titleView = (TextView)view.findViewById(R.id.titleId);
viewHolder.subTitleView = (TextView) view
.findViewById(R.id.subTitleId);
viewHolder.phoneButton = (Button) view
.findViewById(R.id.phoneButton);
viewHolder.emailButton = (Button) view
.findViewById(R.id.emailButton);
viewHolder.infoButton = (Button) view.findViewById(R.id.infoButton);
view.setTag(viewHolder);
} else {
view = convertView;
}
final ViewHolder holder = (ViewHolder) view.getTag();
holder.infoButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
holder.infoButton.setText("Applied");
}
});
holder.titleView.setText(list.get(position).getFederalTitle());
holder.subTitleView.setText(list.get(position).getFederalSubTitle());
return view;
}
}