Bonsoir,

Je débute encore sous Android, et voici ma situation : mon activité principale est une TabActivity dans laquelle chaque onglet démarre une nouvelle Activity.


Voici mon activity qui plante lors du click sur un item ou en appuyant sur la touche "retour" pour quitter

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
package Tarabbia.Xamax;
 
import java.util.ArrayList;
import java.util.HashMap;
 
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
 
public class Xamax_tab extends Activity {
	private ListView maListViewPerso;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
 
        //Récupération de la listview créée dans le fichier main.xml
        maListViewPerso = (ListView) findViewById(R.id.listviewperso);
 
        //Création de la ArrayList qui nous permettra de remplire la listView
        ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
 
        //On déclare la HashMap qui contiendra les informations pour un item
        HashMap<String, String> map;
 
        map = new HashMap<String, String>();
        //on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
        map.put("titre", "Word");
        //on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
        map.put("description", "Editeur de texte");
        //on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
        map.put("img", String.valueOf(R.drawable.tab));
        //enfin on ajoute cette hashMap dans la arrayList
        listItem.add(map);
 
        //On refait la manip plusieurs fois avec des données différentes pour former les items de notre ListView
 
        map = new HashMap<String, String>();
        map.put("titre", "Excel");
        map.put("description", "Tableur");
        map.put("img", String.valueOf(R.drawable.tab));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Power Point");
        map.put("description", "Logiciel de présentation");
        map.put("img", String.valueOf(R.drawable.tab));
        listItem.add(map);
 
        map = new HashMap<String, String>();
        map.put("titre", "Outlook");
        map.put("description", "Client de courrier électronique");
        map.put("img", String.valueOf(R.drawable.tab));
        listItem.add(map);
 
        //Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
        SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.affichageitem,
               new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
 
        //On attribut à notre listView l'adapter que l'on vient de créer
        maListViewPerso.setAdapter(mSchedule);
 
        //Enfin on met un écouteur d'évènement sur notre listView
        maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
			@Override
        	@SuppressWarnings("unchecked")
         	public void onItemClick(AdapterView<?> a, View v, int position, long id) {
 
        		try {
        			//on récupère la HashMap contenant les infos de notre item (titre, description, img)
            		HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
 
            		AlertDialog alertDialog = new AlertDialog.Builder(Xamax_tab.this).create();
            		alertDialog.setTitle("Reset...");
            		alertDialog.setMessage("R u sure?");
            		alertDialog.setButton3("OK", new DialogInterface.OnClickListener() {
            		      public void onClick(DialogInterface dialog, int which) {
 
            		       finish();
 
            		    } });
            		alertDialog.setIcon(android.R.drawable.alert_dark_frame);
            		alertDialog.show();
            		finish();
				} catch (Exception e) {
					e.printStackTrace();
				}
        	}
         });
 
    }
 
 
}
Mon activité qu'appelle l'activité qui plante:

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
super.onCreate(savedInstanceState);
	    //setContentView(R.layout.main);
 
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost tabs;
	    tabs = (TabHost) findViewById(android.R.id.tabhost);
 
        LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);
        tabHost.setup(); 
        tabHost.addTab(tabHost.newTabSpec("Xamax_tab").setIndicator("Xamax tab",this.getResources().getDrawable(R.drawable.tab)).setContent(new Intent(this, Xamax_tab.class)));
        tabHost.addTab(tabHost.newTabSpec("Xamax_jt").setIndicator("Xamax jt",this.getResources().getDrawable(android.R.drawable.ic_menu_agenda)).setContent(new Intent(this, Xamax_jt.class)));
 
	    tabHost.setCurrentTab(0);
 
	    tabs.setup();

Mon layout:

Code XML : 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
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/back_xamax"
        >
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
 
            <ListView 
                android:id="@+id/listviewperso"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" 
                android:text="this is a third tab" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

J'ai cherché un long moment sur des problèmes de Thread, activité, le logcat m'informe d'une erreur: "fatal exception".

source: https://sites.google.com/site/jtarabbia/fichiers

Merci.