IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants graphiques Android Discussion :

Affichage dans TextView avec SQLITE


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    367
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 367
    Par défaut Affichage dans TextView avec SQLITE
    Bonjour

    Je veux remplir deux textview avec une requete SQLite, je n'ai pas d'erreur sur mon code, mais pas d'affichage j'ai une fermeture de l'appli sur le simulateur

    J'ai fait un SqlHelper.java

    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
    public class SqlHelperInscrit extends SQLiteOpenHelper{
    	public static final String DATABASE_PATH = "/data/data/com.wtp.applimultipage/databases/";
    	public static final String DATABASE_NAME = "inscriptionsBD";
    	public static final String TABLE_NAME = "Inscrits";
    	public static final String COLUMN_ID = "_id";
    	public static final String COLUMN_NOM = "nom";
    	public static final String COLUMN_PRENOM = "prenom";
    	public SQLiteDatabase dbSqlite;
    	private final Context myContext;
     
    	public SqlHelperInscrit(Context context) {
    		super(context, DATABASE_NAME, null, 1);
    		this.myContext = context;
     
    	}
    	@Override
    	public void onCreate(SQLiteDatabase db) {
    		// check if exists and copy database from resource
    		createDB();
    	}
    	@Override
    	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    		Log.w("SqlHelperInscrit", "Upgrading database from version " + oldVersion
    				+ " to " + newVersion + ", which will destroy all old data");
    		onCreate(db);
    	}
    	public void createDatabase() {
    		createDB();
    	}
    	private void createDB() {
    		boolean dbExist = DBExists();
    		if (!dbExist) {
    			copyDBFromResource();
    		}
    	}
    	private boolean DBExists() {
    		SQLiteDatabase db = null;
    		try {
    			String databasePath = DATABASE_PATH + DATABASE_NAME;
    			db = SQLiteDatabase.openDatabase(databasePath, null,
    					SQLiteDatabase.OPEN_READWRITE);
    			db.setLocale(Locale.getDefault());
    			db.setLockingEnabled(true);
    			db.setVersion(1);
    		} catch (SQLiteException e) {
    			Log.e("SqlHelperInscrit", "database not found");
    		}
    		if (db != null) {
    			db.close();
    		}
    		return db != null ? true : false;
    	}
    	private void copyDBFromResource() {
    		InputStream inputStream = null;
    		OutputStream outStream = null;
    		String dbFilePath = DATABASE_PATH + DATABASE_NAME;
    		try {
    			inputStream = myContext.getAssets().open(DATABASE_NAME);
    			outStream = new FileOutputStream(dbFilePath);
    			byte[] buffer = new byte[1024];
    			int length;
    			while ((length = inputStream.read(buffer)) > 0) {
    				outStream.write(buffer, 0, length);
    			}
    			outStream.flush();
    			outStream.close();
    			inputStream.close();
    		} catch (IOException e) {
    			throw new Error("Problem copying database from resource file.");
    		}
    	}
    	public void openDataBase() throws SQLException {
    		String myPath = DATABASE_PATH + DATABASE_NAME;
    		dbSqlite = SQLiteDatabase.openDatabase(myPath, null,
    				SQLiteDatabase.OPEN_READWRITE);
    	}
    	@Override
    	public synchronized void close() {
    		if (dbSqlite != null)
    			dbSqlite.close();
    		super.close();
    	}
    	public Cursor getCursor() {
    		SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();
    		queryBuilder.setTables(TABLE_NAME);
    		String[] asColumnsToReturn = new String[] { COLUMN_ID,
    				COLUMN_NOM, COLUMN_PRENOM };
    		Cursor mCursor = queryBuilder.query(dbSqlite, asColumnsToReturn, null,
    				null, null, null, "nom ASC");
    		return mCursor;
    	}
    	public void clearSelections() {
    		ContentValues values = new ContentValues();
    		values.put(" selected", 0);
    		this.dbSqlite.update(SqlHelperInscrit.TABLE_NAME, values, null, null);
    	}
    }
    et ma page d'affichage

    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
    public class page_1_2 extends SimpleCursorAdapter {
    	private Context context;
    	private Cursor currentCursor;
    	public page_1_2(Context context, int layout, Cursor c,
    			String[] from, int[] to, SqlHelperInscrit dbHelper) {
    		super(context, layout, c, from, to);
    		this.currentCursor = c;
    		this.context = context;
    	}
    	public View getView(int pos, View inView, ViewGroup parent) {
    		View v = inView;
    		if (v == null) {
    			LayoutInflater inflater = (LayoutInflater) context
    					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    			v = inflater.inflate(R.layout.page_1_2, null);
    		}
    		this.currentCursor.moveToPosition(pos);
    				TextView voirNom = (TextView) v.findViewById(R.id.lenom);
    		voirNom.setText(this.currentCursor.getString(this.currentCursor
    				.getColumnIndex(SqlHelperInscrit.COLUMN_NOM)));
    				TextView voirPrenom = (TextView) v.findViewById(R.id.leprenom);
    		voirPrenom.setText(this.currentCursor.getString(this.currentCursor
    				.getColumnIndex(SqlHelperInscrit.COLUMN_PRENOM)));
    			return (v);
    	}
    }
    Pouvez-vous m'indiquer s'il y a erreur
    Merci
    JCM

  2. #2
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Salut.

    Tu pourrais nous passer le logcast , pour voir comment sort l'appli ?

    Tu es un peu cavalier sur cette ligne this.currentCursor.moveToPosition(pos);
    De plus à aucun moment tu vérifie si ton Cursor n'est pas vide ou null .

    Je te conseille aussi de mettre plus de log , tu pourras ainsi suivre le fonctionnement de ton application pour savoir.

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    367
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 367
    Par défaut
    voici le logcast

    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
    12-21 09:31:25.258: DEBUG/AndroidRuntime(382): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    12-21 09:31:25.268: DEBUG/AndroidRuntime(382): CheckJNI is ON
    12-21 09:31:25.568: DEBUG/AndroidRuntime(382): --- registering native functions ---
    12-21 09:31:25.918: DEBUG/ddm-heap(382): Got feature list request
    12-21 09:31:26.648: DEBUG/PackageParser(51): Scanning package: /data/app/vmdl61043.tmp
    12-21 09:31:26.868: INFO/PackageManager(51): Removing non-system package:com.wtp.applimultipage
    12-21 09:31:26.868: DEBUG/PackageManager(51): Removing package com.wtp.applimultipage
    12-21 09:31:26.878: DEBUG/PackageManager(51):   Activities: com.wtp.applimultipage.main com.wtp.applimultipage.page_1_1 com.wtp.applimultipage.page_1_2 com.wtp.applimultipage.page_2_1 com.wtp.applimultipage.page_2_2 com.wtp.applimultipage.page_3_1 com.wtp.applimultipage.page_3_2 com.wtp.applimultipage.page_3_3
    12-21 09:31:26.998: DEBUG/PackageManager(51): Scanning package com.wtp.applimultipage
    12-21 09:31:27.008: INFO/PackageManager(51): /data/app/vmdl61043.tmp changed; unpacking
    12-21 09:31:27.028: DEBUG/installd(31): DexInv: --- BEGIN '/data/app/vmdl61043.tmp' ---
    12-21 09:31:27.448: DEBUG/dalvikvm(388): DexOpt: load 63ms, verify 164ms, opt 3ms
    12-21 09:31:27.468: DEBUG/installd(31): DexInv: --- END '/data/app/vmdl61043.tmp' (success) ---
    12-21 09:31:27.481: DEBUG/ActivityManager(51): Uninstalling process com.wtp.applimultipage
    12-21 09:31:27.488: DEBUG/ActivityManager(51): Force removing process ProcessRecord{43bcfb78 372:com.wtp.applimultipage/10045} (com.wtp.applimultipage/10045)
    12-21 09:31:27.528: INFO/Process(51): Sending signal. PID: 372 SIG: 9
    12-21 09:31:27.558: DEBUG/PackageManager(51):   Activities: com.wtp.applimultipage.main com.wtp.applimultipage.page_1_1 com.wtp.applimultipage.page_1_2 com.wtp.applimultipage.page_2_1 com.wtp.applimultipage.page_2_2 com.wtp.applimultipage.page_3_1 com.wtp.applimultipage.page_3_2 com.wtp.applimultipage.page_3_3
    12-21 09:31:27.618: WARN/UsageStats(51): Unexpected resume of com.wtp.ishopadom while already resumed in com.wtp.applimultipage
    12-21 09:31:27.648: INFO/WindowManager(51): WIN DEATH: Window{43c61c90 com.wtp.applimultipage/com.wtp.applimultipage.main paused=false}
    12-21 09:31:27.708: DEBUG/ActivityManager(51): Received spurious death notification for thread android.os.BinderProxy@43cd1118
    12-21 09:31:27.788: WARN/InputManagerService(51): Got RemoteException sending setActive(false) notification to pid 372 uid 10045
    12-21 09:31:27.988: INFO/installd(31): move /data/dalvik-cache/data@app@vmdl61043.tmp@classes.dex -> /data/dalvik-cache/data@app@com.wtp.applimultipage.apk@classes.dex
    12-21 09:31:27.998: DEBUG/PackageManager(51): New package installed in /data/app/com.wtp.applimultipage.apk
    12-21 09:31:28.168: DEBUG/AndroidRuntime(382): Shutting down VM
    12-21 09:31:28.178: DEBUG/dalvikvm(382): DestroyJavaVM waiting for non-daemon threads to exit
    12-21 09:31:28.188: DEBUG/dalvikvm(382): DestroyJavaVM shutting VM down
    12-21 09:31:28.188: DEBUG/dalvikvm(382): HeapWorker thread shutting down
    12-21 09:31:28.198: DEBUG/dalvikvm(382): HeapWorker thread has shut down
    12-21 09:31:28.198: DEBUG/jdwp(382): JDWP shutting down net...
    12-21 09:31:28.198: INFO/dalvikvm(382): Debugger has detached; object registry had 1 entries
    12-21 09:31:28.218: DEBUG/dalvikvm(382): VM cleaning up
    12-21 09:31:28.230: DEBUG/ActivityManager(51): Uninstalling process com.wtp.applimultipage
    12-21 09:31:28.238: ERROR/AndroidRuntime(382): ERROR: thread attach failed
    12-21 09:31:28.298: DEBUG/dalvikvm(382): LinearAlloc 0x0 used 621260 of 5242880 (11%)
    12-21 09:31:28.718: DEBUG/dalvikvm(51): GC freed 7953 objects / 519224 bytes in 283ms
    12-21 09:31:28.838: WARN/ResourceType(51): Resources don't contain package for resource number 0x7f060000
    12-21 09:31:28.898: WARN/ResourceType(51): Resources don't contain package for resource number 0x7f060001
    12-21 09:31:29.138: DEBUG/dalvikvm(106): GC freed 5301 objects / 295608 bytes in 403ms
    12-21 09:31:29.168: WARN/ResourceType(51): Resources don't contain package for resource number 0x7f060000
    12-21 09:31:29.188: WARN/ResourceType(51): Resources don't contain package for resource number 0x7f060001
    12-21 09:31:29.938: DEBUG/AndroidRuntime(393): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    12-21 09:31:29.981: DEBUG/AndroidRuntime(393): CheckJNI is ON
    12-21 09:31:30.388: DEBUG/AndroidRuntime(393): --- registering native functions ---
    12-21 09:31:30.738: DEBUG/ddm-heap(393): Got feature list request
    12-21 09:31:31.508: INFO/ActivityManager(51): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.wtp.applimultipage/.main }
    12-21 09:31:31.618: INFO/ActivityManager(51): Start proc com.wtp.applimultipage for activity com.wtp.applimultipage/.main: pid=399 uid=10045 gids={}
    12-21 09:31:31.638: DEBUG/AndroidRuntime(393): Shutting down VM
    12-21 09:31:31.638: DEBUG/dalvikvm(393): DestroyJavaVM waiting for non-daemon threads to exit
    12-21 09:31:31.648: DEBUG/dalvikvm(393): DestroyJavaVM shutting VM down
    12-21 09:31:31.658: DEBUG/dalvikvm(393): HeapWorker thread shutting down
    12-21 09:31:31.658: DEBUG/dalvikvm(393): HeapWorker thread has shut down
    12-21 09:31:31.658: DEBUG/jdwp(393): JDWP shutting down net...
    12-21 09:31:31.658: INFO/dalvikvm(393): Debugger has detached; object registry had 1 entries
    12-21 09:31:31.668: DEBUG/dalvikvm(393): VM cleaning up
    12-21 09:31:31.708: ERROR/AndroidRuntime(393): ERROR: thread attach failed
    12-21 09:31:31.768: DEBUG/dalvikvm(393): LinearAlloc 0x0 used 636716 of 5242880 (12%)
    12-21 09:31:32.048: DEBUG/ddm-heap(399): Got feature list request
    12-21 09:31:32.808: INFO/ActivityManager(51): Displayed activity com.wtp.applimultipage/.main: 1203 ms (total 1203 ms)
    12-21 09:31:37.929: DEBUG/dalvikvm(229): GC freed 43 objects / 2072 bytes in 89ms
    12-21 09:31:42.278: WARN/KeyCharacterMap(399): No keyboard for id 0
    12-21 09:31:42.278: WARN/KeyCharacterMap(399): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
    12-21 09:31:48.030: DEBUG/dalvikvm(336): GC freed 233 objects / 10160 bytes in 218ms
    12-21 09:31:50.018: INFO/ActivityManager(51): Starting activity: Intent { cmp=com.wtp.applimultipage/.page_1_2 }
    12-21 09:31:50.198: DEBUG/dalvikvm(399): newInstance failed: no <init>()
    12-21 09:31:50.268: DEBUG/AndroidRuntime(399): Shutting down VM
    12-21 09:31:50.278: WARN/dalvikvm(399): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
    12-21 09:31:50.308: ERROR/AndroidRuntime(399): Uncaught handler: thread main exiting due to uncaught exception
    12-21 09:31:50.378: ERROR/AndroidRuntime(399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.wtp.applimultipage/com.wtp.applimultipage.page_1_2}: java.lang.InstantiationException: com.wtp.applimultipage.page_1_2
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2375)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.os.Handler.dispatchMessage(Handler.java:99)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.os.Looper.loop(Looper.java:123)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.main(ActivityThread.java:4310)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at java.lang.reflect.Method.invokeNative(Native Method)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at java.lang.reflect.Method.invoke(Method.java:521)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at dalvik.system.NativeStart.main(Native Method)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399): Caused by: java.lang.InstantiationException: com.wtp.applimultipage.page_1_2
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at java.lang.Class.newInstanceImpl(Native Method)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at java.lang.Class.newInstance(Class.java:1479)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2367)
    12-21 09:31:50.378: ERROR/AndroidRuntime(399):     ... 11 more
    12-21 09:31:50.438: INFO/Process(51): Sending signal. PID: 399 SIG: 3
    12-21 09:31:50.448: INFO/dalvikvm(399): threadid=7: reacting to signal 3
    12-21 09:31:50.499: INFO/dalvikvm(399): Wrote stack trace to '/data/anr/traces.txt'
    12-21 09:31:53.929: INFO/Process(399): Sending signal. PID: 399 SIG: 9
    12-21 09:31:53.969: INFO/WindowManager(51): WIN DEATH: Window{43c324c8 com.wtp.applimultipage/com.wtp.applimultipage.main paused=false}
    12-21 09:31:53.969: INFO/ActivityManager(51): Process com.wtp.applimultipage (pid 399) has died.
    12-21 09:31:53.989: INFO/WindowManager(51): WIN DEATH: Window{43c428a8 AtchDlg:com.wtp.applimultipage/com.wtp.applimultipage.main paused=false}
    12-21 09:31:54.069: INFO/ActivityManager(51): Start proc com.wtp.applimultipage for activity com.wtp.applimultipage/.main: pid=408 uid=10045 gids={}
    12-21 09:31:54.519: DEBUG/ddm-heap(408): Got feature list request
    12-21 09:31:54.639: WARN/UsageStats(51): Something wrong here, didn't expect com.wtp.applimultipage to be resumed
    12-21 09:31:55.049: WARN/InputManagerService(51): Got RemoteException sending setActive(false) notification to pid 399 uid 10045
    12-21 09:31:55.169: INFO/ActivityManager(51): Displayed activity com.wtp.applimultipage/.main: 1125 ms (total 5020 ms)

  4. #4
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Ton erreur est là
    12-21 09:31:50.378: ERROR/AndroidRuntime(399): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.wtp.applimultipage/com.wtp.applimultipage.page_1_2}: java.lang.InstantiationException: com.wtp.applimultipage.page_1_2
    Maintenant je ne connais pas très bien la class SimpleCursorAdapter
    mais tu dois avoir un souci lors de la création de l'instance de cet objet .

    http://developer.android.com/referen...orAdapter.html

    Comment l'appelles tu ?

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2007
    Messages
    367
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2007
    Messages : 367
    Par défaut
    Je l'appelle à partir d'un menu sur ma page main

    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
    public class main extends ListActivity {
    	private static final int ACTIVITY_PAGE_1_1=0;
    	private static final int ACTIVITY_PAGE_1_2=1;
    	private static final int ACTIVITY_PAGE_2_1=2;
    	private static final int ACTIVITY_PAGE_2_2=3;
    	private static final int ACTIVITY_PAGE_3_1=4;
    	private static final int ACTIVITY_PAGE_3_2=5;
    	private static final int ACTIVITY_PAGE_3_3=5;
    	private static final int VOIR_PAGE_1_1 = Menu.FIRST ;
    	private static final int VOIR_PAGE_1_2 = Menu.FIRST + 1;
    	private static final int VOIR_PAGE_2_1 = Menu.FIRST + 2;
    	private static final int VOIR_PAGE_2_2 = Menu.FIRST + 3;
    	private static final int VOIR_PAGE_3_1 = Menu.FIRST + 4;
    	private static final int VOIR_PAGE_3_2 = Menu.FIRST + 5;
    	private static final int VOIR_PAGE_3_3 = Menu.FIRST + 6;
    	private DBAdapter mDbHelper;
     
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.inscrits_list);
            mDbHelper = new DBAdapter(this);
            mDbHelper.open();
            fillData();
            registerForContextMenu(getListView());
        }
        private void fillData() {
    		Cursor InscritsCursor = mDbHelper.fetchAllInscrits();
            startManagingCursor(InscritsCursor);
            // Create an array to specify the fields we want to display in the list (only TITLE)
            String[] from = new String[]{DBAdapter.KEY_NOM};
            // and an array of the fields we want to bind those fields to (in this case just text1)
            int[] to = new int[]{R.id.lenom};
            // Now create a simple cursor adapter and set it to display
            SimpleCursorAdapter inscrits = 
                new SimpleCursorAdapter(this, R.layout.inscrits_row, InscritsCursor, from, to);
            setListAdapter(inscrits);
    	}
    	@Override
        public boolean onCreateOptionsMenu(Menu menu) {
            super.onCreateOptionsMenu(menu);
            SubMenu m1 = menu.addSubMenu(0,1000,0,"Page 3");
            m1.add(0, VOIR_PAGE_3_1, 0, R.string.menu_3_1);
        	m1.add(0, VOIR_PAGE_3_2, 0, R.string.menu_3_2);
        	m1.add(0, VOIR_PAGE_3_3, 0, R.string.menu_3_3);
        	SubMenu m2 = menu.addSubMenu(0,2000,0,"Page 2");
        	m2.add(0, VOIR_PAGE_2_1, 0, R.string.menu_2_1);
        	m2.add(0, VOIR_PAGE_2_2, 0, R.string.menu_2_2);
        	SubMenu m3 = menu.addSubMenu(0,3000,0,"Page 1");
        	m3.add(0, VOIR_PAGE_1_1, 0, R.string.menu_1_1);
        	m3.add(0, VOIR_PAGE_1_2, 0, R.string.menu_1_2);
            return true;
        }
        @Override
        public boolean onMenuItemSelected(int featureId, MenuItem item) {
            switch(item.getItemId()) {
                case VOIR_PAGE_1_1:
                	Page_1_1();
                    return true;
                case VOIR_PAGE_1_2:
                	Page_1_2();
                	return true;
                case VOIR_PAGE_2_1:
                	Page_2_1();
                	return true;
                case VOIR_PAGE_2_2:
                	Page_2_2();
                	return true;
                case VOIR_PAGE_3_1:
                	Page_3_1();
                	return true;
                case VOIR_PAGE_3_2:
                	Page_3_2();
                	return true;
                case VOIR_PAGE_3_3:
                	Page_3_3();
                	return true;
            }
            return super.onMenuItemSelected(featureId, item);
        }
        private void Page_1_1() {
        	Intent i = new Intent(this, page_1_1.class);
            startActivityForResult(i, ACTIVITY_PAGE_1_1);
    	}
    	private void Page_1_2() {
    		Intent i = new Intent(this, page_1_2.class);
            startActivityForResult(i, ACTIVITY_PAGE_1_2);
    	}
    	private void Page_2_1() {
            Intent i = new Intent(this, page_2_1.class);
            startActivityForResult(i, ACTIVITY_PAGE_2_1);
        }
        private void Page_2_2() {
        	Intent i = new Intent(this, page_2_2.class);
            startActivityForResult(i, ACTIVITY_PAGE_2_2);
    	}
    	private void Page_3_1() {
    		Intent i = new Intent(this, page_3_1.class);
            startActivityForResult(i, ACTIVITY_PAGE_3_1);
    	}
    	private void Page_3_2() {
        	Intent i = new Intent(this, page_3_2.class);
        	startActivityForResult(i, ACTIVITY_PAGE_3_2);
    	}
    	private void Page_3_3() {
        	Intent i = new Intent(this, page_3_3.class);
        	startActivityForResult(i, ACTIVITY_PAGE_3_3);
    	}
       protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
            Intent i = new Intent(this, page_1_1.class);
            i.putExtra(DBAdapter.KEY_ROWID, id);
            startActivityForResult(i, ACTIVITY_PAGE_1_1);
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
            super.onActivityResult(requestCode, resultCode, intent);
            fillData();
       }
    }
    Je me suis inspiré du tuto NotePad3

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Affichage dans JSP avec Struts 2
    Par fruwen7 dans le forum Struts 2
    Réponses: 0
    Dernier message: 10/09/2012, 12h20
  2. [MySQL] problème d'affichage dans tableau avec bdd Mysql
    Par sinifer dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 01/05/2009, 09h50
  3. problème d'affichage dans ruby avec ajax
    Par Lunardirc dans le forum Ruby on Rails
    Réponses: 2
    Dernier message: 23/06/2008, 14h59
  4. Aucun affichage dans formulaire avec onglet
    Par Daniel MOREAU dans le forum Access
    Réponses: 4
    Dernier message: 04/12/2006, 17h59
  5. Affichage d'un résultat selon requête dans formulaire avec date
    Par SMPGSARL dans le forum Requêtes et SQL.
    Réponses: 10
    Dernier message: 06/07/2006, 14h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo