da_st da_st - 1 month ago 13
Android Question

Disable loading spinner when listview content is loaded

I have this code for the listview:

@Override
public void onComplete(List<Profile> friends) {

// populate list
List<String> values = new ArrayList<String>();
for (Profile profile : friends) {
//profile.getInstalled();
values.add(profile.getName());
}

ArrayAdapter<String> friendsListAdapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.list_items2, values);
friendsListAdapter.sort(new Comparator<String>() {
@Override
public int compare(String lhs, String rhs) {
return lhs.compareTo(rhs);
}
});


And this custom spinner with animation:

<ImageView
android:id="@+id/imageSpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="@drawable/custom_spinner2" />


The listview loads content from facebook, and the when the content is done loading i want the spinner to disappear, but what i have now is that the spinner is there even when the content is loaded. This is what i have tried adding to the onComplete method:

runOnUiThread(new Runnable() {
@Override
public void run() {
mSpinner.setVisibility(View.GONE);
}
});


But with this code the spinner is still there when the content is loaded, any ideas what is wrong with the code?

I solved it by adding clearAnimation(); right after the setVisibility(View.GONE);,
like this:

runOnUiThread(new Runnable() {
@Override
public void run() {
mSpinner.setVisibility(View.GONE);
mSpinner.clearAnimation();
}
});


Now it works perfectly!

Answer

I'm guessing this happens because your animation is running always. Just hide your animation on runOnUiThread. Or use default ProgressBar.