我有一个ArrayAdapter
for a GridView
,正如您在代码中看到的那样,我GridView
使用该getView
方法填充了一个名为: 的自定义视图GridViewCell
。
现在单击此自定义视图时,有一个FlipAnimation
方法运行非常适用于单击的视图。我想要实现的是对当前在适配器中的所有其他自定义视图运行相同的动画方法,所以我需要获取所有其他视图的实例(适配器中有 4 个视图,所以我需要获取实例其他 3).
public class AnswersGridAdapter extends ArrayAdapter<Answer>
{
private static final String TAG = AnswersGridAdapter.class.getSimpleName();
private ArrayList<Answer> answersList;
private Context context;
private MainActivity activity;
private QuestionGridFragment fragment;
private View view;
public AnswersGridAdapter(QuestionGridFragment fragment, Context context, int textViewResourceId, ArrayList<Answer> answersList)
{
super(context, textViewResourceId, answersList);
this.answersList = new ArrayList<Answer>();
this.answersList.addAll(answersList);
this.context = context;
this.activity = (MainActivity)context;
this.fragment = fragment;
}
public View getView(final int position, View convertView, ViewGroup parent)
{
final View view = new GridViewCell(context);
if (answersList.get(position).isChecked())
{
((GridViewCell)view).FlipToBackWithoutAnimation();
}
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
((GridViewCell)view).FlipAnmiation();
if (answersList.get(position).isChecked())
{
answersList.get(position).setChecked(false);
}
else
{
answersList.get(position).setChecked(true);
}
activity.getEstimatedCostTextView().setText(String.valueOf(activity.getEstimatedCost()));
fragment.flipOtherChosenAnswer(position);
}
});
((GridViewCell)view).setTextToTitleTextView(answersList.get(position).getAnswerText());
return view;
}
}
我试图做这样的事情:
public void flipOtherChosenAnswer(int position)
{
int cellCount = answersAdapter.getCount();
for (int i=0; i < cellCount; i++ )
{
((GridViewCell)answersAdapter.getView(i, null, null)).FlipAnmiation();
}
}
但这对我没有帮助。如何才能做到这一点?