Problème : ViewSwitcher + ImageButton
Bonjour,
j'essaye de créer un menu de jeu et dans ce menu, j'ai une vue qui permet de sélectionner la campagne (comme suit) :
http://img853.imageshack.us/img853/6...nselection.png
Pour cela, j'ai eu l'idée d'utiliser un ViewSwitcher pour ne pas avoir une Activity par campagne.
Le problème, c'est que le switcher me permet de faire défiler des ImageButton qui sont censés permettre de sélectionner la campagne et d'afficher un aperçu (image) de la campagne (d'où l'ImageButton) et que quand je run l'appli, ça me renvoit l'erreur :
Citation:
06-24 17:32:06.760: WARN/ActivityManager(2690): Trying to launch com.lesmobilizers.jonas.activities/.CampaignSelection
06-24 17:32:06.790: INFO/OrientationDebug(2690): [pwm] in updateOrientationListenerLp()
06-24 17:32:06.790: INFO/OrientationDebug(2690): [pwm] needSensorRunningLp(), return true #1
06-24 17:32:06.790: WARN/dalvikvm(22498): threadid=1: thread exiting with uncaught exception (group=0x40015578)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): FATAL EXCEPTION: main
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lesmobilizers.jonas.activities/com.lesmobilizers.jonas.activities.CampaignSelection}: java.lang.ClassCastException: android.widget.ImageButton
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.os.Looper.loop(Looper.java:123)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread.main(ActivityThread.java:3691)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at java.lang.reflect.Method.invoke(Method.java:507)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at dalvik.system.NativeStart.main(Native Method)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): Caused by: java.lang.ClassCastException: android.widget.ImageButton
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at com.lesmobilizers.jonas.activities.CampaignSelection.onCreate(CampaignSelection.java:29)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
06-24 17:32:06.795: ERROR/AndroidRuntime(22498): ... 11 more
06-24 17:32:06.805: WARN/ActivityManager(2690): Force finishing activity com.lesmobilizers.jonas.activities/.CampaignSelection
06-24 17:32:06.805: ERROR/(2690): Dumpstate > /data/log/dumpstate_app_error
06-24 17:32:06.805: WARN/ActivityManager(2690): Force finishing activity com.lesmobilizers.jonas.activities/.Home
06-24 17:32:06.815: INFO/dumpstate(22567): begin
06-24 17:32:07.305: WARN/ActivityManager(2690): Activity pause timeout for HistoryRecord{40825620 com.lesmobilizers.jonas.activities/.CampaignSelection}
J'ai ce code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| public class CampaignSelection extends Activity {
private ViewSwitcher viewSwitcher;
private Button selectCampaign;
private Button previousCampaign;
private Button nextCampaign;
private Button back;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.campaignselection);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
viewSwitcher = (ViewSwitcher)findViewById(R.id.viewSwitcher);
// Implements the "Select Campaign" button action
this.selectCampaign = (Button) this.findViewById(R.id.selectCampaign);
this.selectCampaign.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
// Implements the "Select Campaign" button action
this.selectCampaign = (Button) this.findViewById(R.id.selectCampaign2);
this.selectCampaign.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
}
});
// Implements the "Previous Campaign" button action
this.previousCampaign = (Button) this.findViewById(R.id.previousCampaign);
this.previousCampaign.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
viewSwitcher.showPrevious();
}
});
// Implements the "Next Campaign" button action
this.nextCampaign = (Button) this.findViewById(R.id.nextCampaign);
this.nextCampaign.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
viewSwitcher.showNext();
}
});
// Implements the "Back" button action
this.back = (Button) this.findViewById(R.id.back);
this.back.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), Home.class);
startActivityForResult(intent, 0);
}
});
}
} |
Et ce layout :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| <?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_width="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_gravity="center"
android:layout_height="wrap_content"
android:id="@+id/previousCampaign"
android:text="<">
</Button>
<ViewSwitcher
android:layout_width="wrap_content"
android:id="@+id/viewSwitcher"
android:layout_height="wrap_content">
<ImageButton
android:layout_width="wrap_content"
android:id="@+id/selectCampaign"
android:layout_height="wrap_content"
android:src="@drawable/icon">
</ImageButton>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon2"
android:id="@+id/selectCampaign2">
</ImageButton>
</ViewSwitcher>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/nextCampaign"
android:text=">">
</Button>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/back"
android:text="Back">
</Button>
</LinearLayout> |
Voilà, si quelqu'un pouvait m'expliquer où est ce que j'fais une erreur ?
Merci ;)