I described the adapter for ListView inherited from ArrayAdapter, however the getView method is called 12 times instead of 4x. The only solution that was found was to set the match_parent parameter in the layout_width and layout_height, but this did not help. How else can you get repeat calls to getView?

Adapter code

public ExecuteAdapter( int resId, ArrayList textPack, ArrayList imagePack, int mainLayout, Data summaryPack, int summaryLayout, Data summaryCommandPack){ super(GlobalActivity.getActivity(), resId, new String[textPack.size()]); this.textPack = textPack; this.imagePack = imagePack; this.mainLayout = mainLayout; this.summaryLayout = summaryLayout; this.summaryPack = summaryPack; this.summaryCommandPack = summaryCommandPack; new LogExt("list size - "+textPack.size()); } public View getView (int pos, View view, ViewGroup parent){ LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); currentView = inflater.inflate(mainLayout, parent, false); linearLayout = (LinearLayout) currentView.findViewById(R.id.linear_layout); loadText(pos); loadImage(pos); createSummaryField(pos); new LogExt("call getView"); return currentView; } 

Log output

 05-20 23:15:45.981 1433-1433/com.example.s D/fileCompīš• list size - 4 05-20 23:15:45.981 1433-1433/com.example.s D/fileCompīš• end load 05-20 23:15:46.011 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.021 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.061 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.071 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.141 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.151 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.161 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.171 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.221 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.251 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.261 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.271 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.301 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.311 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.321 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.351 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.361 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.371 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.371 1433-1433/com.example.s D/fileCompīš• call getView 05-20 23:15:46.381 1433-1433/com.example.s D/fileCompīš• call getView 
  • Yes, ViewHolder helped, thanks. - Kota1921
  • Yes, here not only the ViewHolder is needed, but also the additional condition that the View is already created, which is actually described in any normal guide. But in general, getView can twitch quite often, and this is a personal matter of ListView. There is no need to lay in the fact that getView will twitch for a certain number of times or in some particular order. - KoVadim

1 answer 1

in order for each new item of the list to re-create it again, use ViewHolder in the adapter