The getView()
method in my CustomAdapter
is called every time I scroll up or down.
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if (convertView == null) {
vi = inflater.inflate(R.layout.projectlist, null);
holder = new ViewHolder();
holder.projectTitelTextView = (TextView) vi.findViewById(R.id.projectTitle);
holder.projectInfoTextView = (TextView) vi.findViewById(R.id.projectInfo);
holder.projectImageImageView = (ImageView) vi.findViewById(R.id.projectImage);
holder.projectDeadline = (TextView) vi.findViewById(R.id.projectdeadline);
vi.setTag(holder);
} else {
holder = (ViewHolder) vi.getTag();
}
if (projectItems.size() <= 0) {
[...]
} else {
[...]
}
}
return vi;
}
The ListView
XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/container"
android:layout_width="match_parent" android:layout_height="match_parent"
tools:context=".MainActivity" tools:ignore="MergeRootFrame">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/android:list"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:focusable="false"
android:clickable="false"
android:smoothScrollbar="true" />
</LinearLayout>
Why it is called every time I scroll up or down?
Assuming, I have 10 Items displayed. If I scroll down, the getView()
called one time and it show me one more Item. If I hard scroll and want to go to the end of the list. It get called multiple times until the data is loaded and displayed.
If I want to scroll then up, the same scenario happens.
What can I do to prevent calling multiple times getView()
or is it necessary?
Kind Regards