Bonjour,
Je suis une débutante en développement Android et je suis en train de développer mon application.
Je viens tout d'abord de faire deux listes, la première Accueil, podcasts, Video, Photos, Nos Programmes et la deuxième, c'est lors je clique sur un item il me donne les items correspondants (celle identique à Facebook application) en utilisant le slide.
J'arrive à faire le slide mais lorsque je clique sur slide pour m'afficher menu principale, le slide a disparu et ne s'affiche pas.
Voila mon code ci-jointe :
Le 1er est le code du slide et le 2ème est le code de deux menus où il y a le problème :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package my.mosaique.fm; import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.TextView; public class acceuil extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // storing string resources into Array String[] adobe_products = getResources().getStringArray(R.array.adobe_products); // Binding Array to ListAdapter this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item1, R.id.label, adobe_products)); ListView lv = getListView(); // listening to single list item on click lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // selected item String product = ((TextView) view).getText().toString(); // Launching new Activity on selecting single List Item Intent i = new Intent(getApplicationContext(), MosaiqueActivity.class); // sending data to new activity i.putExtra("product", product); startActivity(i); } }); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 package my.mosaique.fm; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; public class entree extends Activity { private static final int STOPSPLASH = 0; private static final long SPLASHTIME = 3000; private Handler splashHandler = new Handler() { @Override public void handleMessage(Message msg) { ; switch (msg.what) { case STOPSPLASH: //remove SplashScreen from view Intent intent = new Intent(entree.this, MosaiqueActivity.class); startActivity(intent); break; } super.handleMessage(msg); } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.entree); Message msg = new Message(); msg.what = STOPSPLASH; splashHandler.sendMessageDelayed(msg, SPLASHTIME); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 package my.mosaique.fm; import java.util.Date; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.ListView; /** * Simple Activity that uses each Button in the layout to invoke an Activity. */ public class MosaiqueActivity extends Activity implements AnimationListener { View app; acceuil menu; Bundle objetbunble = new Bundle(); boolean menuOut = false; AnimParams animParams = new AnimParams(); class ClickListener implements OnClickListener { @Override public void onClick(View v) { System.out.println("onClick " + new Date()); MosaiqueActivity me = MosaiqueActivity.this; Context context = me; Animation anim; int w = app.getMeasuredWidth(); int h = app.getMeasuredHeight(); int left = (int) (app.getMeasuredWidth() * 0.8); if (!menuOut) { //anim = AnimationUtils.loadAnimation(context, R.anim.push_right_out_80); anim = new TranslateAnimation(0, left, 0, 0); //On créé l'Intent qui va nous permettre d'afficher l'autre Activity //Attention il va surement falloir que vous modifier le premier paramètre (Tutoriel9_Android.this) //Mettez le nom de l'Activity dans la quelle vous êtes actuellement Intent intent = new Intent(MosaiqueActivity.this, acceuil.class); //On affecte à l'Intent le Bundle que l'on a créé intent.putExtras(objetbunble); //On démarre l'autre Activity startActivity(intent); animParams.init(left, 0, left + w, h); } else { // anim = AnimationUtils.loadAnimation(context, R.anim.push_left_in_80); anim = new TranslateAnimation(0, -left, 0, 0); animParams.init(0, 0, w, h); } anim.setDuration(500); anim.setAnimationListener(me); //Tell the animation to stay as it ended (we are going to set the app.layout first than remove this property) anim.setFillAfter(true); // Only use fillEnabled and fillAfter if we don't call layout ourselves. // We need to do the layout ourselves and not use fillEnabled and fillAfter because when the anim is finished // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved. // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does // work. // anim.setFillEnabled(true); // anim.setFillAfter(true); app.startAnimation(anim); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slide_animation_then_call_layout); // menu = findViewById(R.id.menu); app = findViewById(R.id.app); // ViewUtils.printView("menu", menu); ViewUtils.printView("app", app); //On créé un objet Bundle, c'est ce qui va nous permetre d'envoyer des données à l'autre Activity ListView listView = (ListView) app.findViewById(R.id.list); // ListView listView1 = (ListView) menu.findViewById(R.id.list1); ViewUtils.initListView(this, listView, "Item ", 10, android.R.layout.simple_list_item_1);// 10 c'est le nombre item dans listview //ViewUtils.initListView(this, listView1, "AAAAA ", 7, android.R.layout.simple_list_item_1); // menu.setVisibility(View.VISIBLE); app.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener()); //menu.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener()); } void layoutApp(boolean menuOut) { System.out.println("layout [" + animParams.left + "," + animParams.top + "," + animParams.right + "," + animParams.bottom + "]"); app.layout(animParams.left, animParams.top, animParams.right, animParams.bottom); //Now that we've set the app.layout property we can clear the animation, flicker avoided :) app.clearAnimation(); } @Override public void onAnimationEnd(Animation animation) { System.out.println("onAnimationEnd"); // ViewUtils.printView("menu", menu); ViewUtils.printView("app", app); menuOut = !menuOut; if (!menuOut) { //On créé l'Intent qui va nous permettre d'afficher l'autre Activity //Attention il va surement falloir que vous modifier le premier paramètre (Tutoriel9_Android.this) //Mettez le nom de l'Activity dans la quelle vous êtes actuellement Intent intent = new Intent(MosaiqueActivity.this, acceuil.class); //On affecte à l'Intent le Bundle que l'on a créé intent.putExtras(objetbunble); //On démarre l'autre Activity startActivity(intent); } layoutApp(menuOut); } public void onAnimationRepeat(Animation animation) { System.out.println("onAnimationRepeat"); } @Override public void onAnimationStart(Animation animation) { System.out.println("onAnimationStart"); } static class AnimParams { int left, right, top, bottom; void init(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } //setContentView(contentView); } }voila layout
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package my.mosaique.fm; import android.content.Context; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; /** * Utility methods for Views. */ public class ViewUtils { private ViewUtils() { } public static void setViewWidths(View view, View[] views) { int w = view.getWidth(); int h = view.getHeight(); for (int i = 0; i < views.length; i++) { View v = views[i]; v.layout((i + 1) * w, 0, (i + 2) * w, h); printView("view[" + i + "]", v); } } public static void printView(String msg, View v) { System.out.println(msg + "=" + v); if (null == v) { return; } System.out.print("[" + v.getLeft()); System.out.print(", " + v.getTop()); System.out.print(", w=" + v.getWidth()); System.out.println(", h=" + v.getHeight() + "]"); System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); } public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // By using setAdpater method in listview we an add string array in list. String[] arr = new String[numItems]; for (int i = 0; i < arr.length; i++) { arr[i] = prefix + (i ); } listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Context context = view.getContext(); String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); Toast.makeText(context, msg, 1000).show(); System.out.println(msg); } }); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 /* * #%L * SlidingMenuDemo * $Id:$ * $HeadURL:$ * %% * Copyright (C) 2012 Paul Grime * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">http://www.apache.org/licenses/LICENSE-2.0</a> * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * #L% */ package my.mosaique.fm; import android.content.Context; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; /** * Utility methods for Views. */ public class ViewUtils { private ViewUtils() { } public static void setViewWidths(View view, View[] views) { int w = view.getWidth(); int h = view.getHeight(); for (int i = 0; i < views.length; i++) { View v = views[i]; v.layout((i + 1) * w, 0, (i + 2) * w, h); printView("view[" + i + "]", v); } } public static void printView(String msg, View v) { System.out.println(msg + "=" + v); if (null == v) { return; } System.out.print("[" + v.getLeft()); System.out.print(", " + v.getTop()); System.out.print(", w=" + v.getWidth()); System.out.println(", h=" + v.getHeight() + "]"); System.out.println("mw=" + v.getMeasuredWidth() + ", mh=" + v.getMeasuredHeight()); System.out.println("scroll [" + v.getScrollX() + "," + v.getScrollY() + "]"); } public static void initListView(Context context, ListView listView, String prefix, int numItems, int layout) { // By using setAdpater method in listview we an add string array in list. String[] arr = new String[numItems]; for (int i = 0; i < arr.length; i++) { arr[i] = prefix + (i ); } listView.setAdapter(new ArrayAdapter<String>(context, layout, arr)); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Context context = view.getContext(); String msg = "item[" + position + "]=" + parent.getItemAtPosition(position); Toast.makeText(context, msg, 1000).show(); System.out.println(msg); } }); } }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp"> </TextView>]
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:id="@+id/menu" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#ffff00"> <ListView android:id="@+id/list1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff00ffff" android:cacheColorHint="#ff00ffff" > </ListView> </LinearLayout> <LinearLayout android:id="@+id/app" android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="#ffffffff"> <Button android:id="@+id/BtnSlide" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Slide" /> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff00ff00" android:cacheColorHint="#ff00ff00" > </ListView> </LinearLayout> </FrameLayout>Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="adobe_products"> <item>Acceuil</item> <item>Actualité</item> <item>Podcasts</item> <item>Videos</item> <item>Photo</item> <item>Programme</item> <item>WebVideo</item> </string-array> </resources>
Merci d'avance pour votre aide.
Partager