Iam trying to have an animation inside a dialog
box so it would look like the animation is in front of the activity and be gone after 2 sec, but it always crash and only show the layout
, not the animation, here are my codes:
Method in my MainActivity.java
public void connectedAnim(){
Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.connected);
dialog.getWindow().setBackgroundDrawable(newColorDrawable(Color.TRANSPARENT));
IVcon = (ImageView)findViewById(R.id.IVcon);
IVcon.setBackgroundResource(R.anim.connected);
final AnimationDrawable animcon = (AnimationDrawable)IVcon.getDrawable();
dialog.setCancelable(true);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
animcon.start();
}
});
dialog.show();
}
layout/connected.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:id="@+id/IVcon"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
anim/connected.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/connected" android:duration="500"/>
<item android:drawable="@drawable/disconnected" android:duration="500"/>
</animation-list>
LogCat
java.lang.NullPointerExceptionat com.ardudroid.sample.bluetoothswitch.MainActivity$7.onShow(MainActivity.java:205) at android.app.Dialog$ListenersHandler.handleMessage(Dialog.java:1260) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:153) at android.app.ActivityThread.main(ActivityThread.java:5071) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method)
Line 205:
animcon.start();