у меня есть эта проблема в моем коде, что когда я делаю переход на одной кнопке в средстве просмотра, который выполняется в Onclicklistener, происходит несколько переходов в разных строках, т.е. если я нажимаю кнопку в строке 1, то кнопка перемещается вправо, что ожидается, но кнопка в строке 6 также перемещается вправо, что не ожидается. я проверил, что идентификатор перехода кнопки в строке 1 такой же, как кнопка в строке 6, я не знаю, что не так с моим кодом. пожалуйста помоги. проверьте мой код.
public class UserCustomAdapter extends ArrayAdapter<User> {
Context context;
int layoutResourceId;
ArrayList data = new ArrayList();
String weekDay;
AlertDialog alert;
public UserCustomAdapter(Context context, int layoutResourceId,
ArrayList<User> data, String weekDay) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.weekDay = weekDay;
}
@Override
public View getView(final int position, final View convertView, final
ViewGroup parent) {
View row = convertView;
final UserHolder holder;
if (row == null) {
LayoutInflater inflater1 = ((Activity) context).getLayoutInflater();
row = inflater1.inflate(layoutResourceId, parent, false);
holder = new UserHolder();
holder.subject = (TextView) row.findViewById(R.id.subject);
holder.percentage = (TextView) row.findViewById(R.id.percentage_edit);
holder.attended = (Button) row.findViewById(R.id.attended);
holder.bunked = (Button) row.findViewById(R.id.bunked);
holder.other = (Button) row.findViewById(R.id.other);
row.setTag(holder);
}
else {
holder = (UserHolder) row.getTag();
}
//to set the text into the fields
User user = (User) data.get(position);
holder.subject.setText(user.getName());
holder.percentage.setText(user.getAddress());
holder.attended.setId(position);
holder.bunked.setId(position);
holder.other.setId(position);
holder.attended.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// FOR ANIMATIONS OF BUTTONS
TranslateAnimation translate = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.28f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
translate.setDuration(600);
holder.attended.startAnimation(translate);
Log.d("trans", holder.attended + "");
translate.setFillAfter(true);
TranslateAnimation translate1 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
translate1.setDuration(600);
holder.other.startAnimation(translate1);
translate1.setFillAfter(true);
TranslateAnimation translate2 = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f);
translate2.setDuration(600);
holder.bunked.startAnimation(translate2);
translate2.setFillAfter(true);
}
});
return row;
}
static class UserHolder {
TextView subject;
TextView percentage;
Button attended;
Button bunked;
Button other;
}
}