0

在需要滚动时屏幕填满行后,列表视图的第一项会丢失。直到第 7 或第 8 个项目,第一行是可见的,但在第 8 行之后它会丢失。滚动开始后,除了第一行丢失外,一切都正常了。下面是寻求帮助的代码。

public class ProfileArrayAdapter extends ArrayAdapter<Results> {


private Context mContext;

public ProfileArrayAdapter(Context context, int resource, ArrayList<Results> resultsArrayList) {
    super(context, resource, resultsArrayList);
    this.mContext =context;
}


static class ViewHolder {
    TextView questionIdView;
    TextView testTypeView;
    TextView correctAnswerCountView;
    TextView wrongAnswerCountView;
    TextView emptyAnswerCountView;
    TextView testDateView;
    TextView successRateView;
}


@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    View convertView = view;
    ViewHolder viewHolder;
    Results results = getItem(position);
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.overall_summary_template, viewGroup, false);
        viewHolder = new ViewHolder();
        viewHolder.questionIdView = (TextView) convertView.findViewById(R.id.overall_question_id);
        viewHolder.testTypeView = (TextView) convertView.findViewById(R.id.overall_test_type);
        viewHolder.correctAnswerCountView = (TextView) convertView.findViewById(R.id.overall_correct_answer);
        viewHolder.wrongAnswerCountView = (TextView) convertView.findViewById(R.id.overall_wrong_answer);
        viewHolder.emptyAnswerCountView = (TextView) convertView.findViewById(R.id.overall_empty_answer);
        viewHolder.testDateView = (TextView) convertView.findViewById(R.id.overall_test_date);
        viewHolder.successRateView = (TextView) convertView.findViewById(R.id.success_rate);
        convertView.setTag(viewHolder);

    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    String testId = " #" + results.getItemTestIdString();
    viewHolder.questionIdView.setText(testId);
    String testType = results.getItemTestType();
    viewHolder.testTypeView.setText(testType);
    String testDate = results.getItemTestDate();
    viewHolder.testDateView.setText(testDate);
    String wrongOnesText = mContext.getString(R.string.wrong_summary);
    String falseOnes = wrongOnesText + String.valueOf(results.getItemNumberOfFalseAnswers());
    viewHolder.wrongAnswerCountView.setText(falseOnes);
    String emptyOnesText = mContext.getString(R.string.empty_summary);
    String emptyOnes = emptyOnesText + String.valueOf(results.getItemNumberOfEmptyAnswers());
    viewHolder.emptyAnswerCountView.setText(emptyOnes);
    String correctOnesText = mContext.getString(R.string.correct_summary);
    String correctOnes = correctOnesText + String.valueOf(results.getItemNumberOfCorrectAnswers());
    viewHolder.correctAnswerCountView.setText(correctOnes);
    String successRate = "% " + results.getItemSuccessRate();
    viewHolder.successRateView.setText(successRate);
    return convertView;
}

}
4

1 回答 1

0

覆盖两个方法getItemId()getItemViewType()适配器本身..并使它们都返回默认的返回语句(位置)并检查。

于 2017-12-30T20:18:52.877 回答