在需要滚动时屏幕填充行后,listview的第一项会丢失。直到第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;
}
}
答案 0 :(得分:0)
在适配器本身中覆盖两个方法getItemId()
和getItemViewType()
..并使它们都返回默认的return语句(位置)并检查。