当我滚动ListView时为什么再次调用它相应的适配器?
我需要避免这种情况,因为当我滚动ListView
时会产生延迟有什么人可以做什么?
编辑:这是我的适配器
public class CustomAdapter extends ArrayAdapter<MatchDTO> {
public CustomAdapter(Context context, int resource, int textViewResourceId, List<MatchDTO> matches) {
super(context, resource, textViewResourceId, matches);
}
@Override
public View getView(int position, View convertView, ViewGroup mainViewGroup) {
try {
ViewHolder viewHolder = null;
if (convertView == null) {
inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.matches_list, null);
viewHolder = new ViewHolder();
viewHolder.homeGoals = (TextView) convertView.findViewById(R.id.home_goals);
viewHolder.awayGoals = (TextView) convertView.findViewById(R.id.away_goals);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
MatchDTO match = matches.get(position);
viewHolder.homeGoals.setText(String.valueOf(match.getHomeGoals()));
viewHolder.awayGoals.setText(String.valueOf(match.getAwayGoals()));
} catch (Exception exception) {
}
return convertView;
}
class ViewHolder {
TextView homeGoals;
TextView awayGoals;
}
}
答案 0 :(得分:0)
请阅读此http://lucasr.org/2012/04/05/performance-tips-for-androids-listview/
并添加adapter.notifydatasetchanged()
您在主要活动中调用CustomAdapter类的地方