CustomLoading in android (error: expected resource of type drawable)
Can anyone recommend a better way for CustomLoading in an Android project.
i using this post .
my code:
_readNewsAsyncTaskManager = new ReadNewsAsyncTaskManager();
_loadigIcon.setImageResource(R.anim.loading_animation);// Error*
loadingViewAnim = (AnimationDrawable) _loadigIcon.getBackground();
// This line is to start Asyn Task only when OnCreate Method get completed, So Loading Icon Rotation Animation work properly
_loadigIcon.post(new Starter());
Error *: expected resource of type drawable
loading_animation:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_loading_1" android:duration="50" />
<item android:drawable="@drawable/ic_loading_2" android:duration="50" />
<item android:drawable="@drawable/ic_loading_3" android:duration="50" />
<item android:drawable="@drawable/ic_loading_4" android:duration="50" />
<item android:drawable="@drawable/ic_loading_5" android:duration="50" />
<item android:drawable="@drawable/ic_loading_6" android:duration="50" />
<item android:drawable="@drawable/ic_loading_7" android:duration="50" />
<item android:drawable="@drawable/ic_loading_8" android:duration="50" />
<item android:drawable="@drawable/ic_loading_9" android:duration="50" />
<item android:drawable="@drawable/ic_loading_10" android:duration="50" />
<item android:drawable="@drawable/ic_loading_11" android:duration="50" />
<item android:drawable="@drawable/ic_loading_12" android:duration="50" />
<item android:drawable="@drawable/ic_loading_13" android:duration="50" />
<item android:drawable="@drawable/ic_loading_14" android:duration="50" />
<item android:drawable="@drawable/ic_loading_15" android:duration="50" />
<item android:drawable="@drawable/ic_loading_16" android:duration="50" />
<item android:drawable="@drawable/ic_loading_17" android:duration="50" />
<item android:drawable="@drawable/ic_loading_18" android:duration="50" />
<item android:drawable="@drawable/ic_loading_19" android:duration="50" />
</animation-list>
source to share
My decision:
Forget this post
move the load_animation file from the animation folder to the dropdown folder
and the load_animation file:
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:duration="50">
<clip
android:clipOrientation="horizontal"
android:drawable="@drawable/ic_loading_1"
/>
</item>
<item android:duration="50">
<clip
android:clipOrientation="horizontal"
android:drawable="@drawable/ic_loading_2"
/>
</item>
<item android:duration="50">
<clip
android:clipOrientation="horizontal"
android:drawable="@drawable/ic_loading_3"
/>
</item>
<item android:duration="50">
<clip
android:clipOrientation="horizontal"
android:drawable="@drawable/ic_loading_4"
/>
</item>
<item android:duration="50">
<clip
android:clipOrientation="horizontal"
android:drawable="@drawable/ic_loading_5"
/>
</item>
</animation-list>
and i using this:
<ProgressBar
android:layout_width="32sp"
android:layout_height="32sp"
android:layout_gravity="center_vertical|center_horizontal"
android:id="@+id/progressBar"
android:indeterminateDrawable="@drawable/loading_animation"/>
source to share
This is not a compiler error. This is just an editor validation error (lint warning) as this is not the usual way to work with Drawable.
There are 2 solutions:
-
Move the load_animation file from the animation folder to the dropdown folder
-
Replace
_loadigIcon.setImageResource(R.anim.loading_animation);
with_loadigIcon.setImageResource(+R.anim.loading_animation);
Link to answer: Android - Expected Type Id Resource
source to share