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

Android Discussion :

selectionner des elements à partir d'une base sqlite


Sujet :

Android

  1. #1
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2009
    Messages : 135
    Points : 110
    Points
    110
    Par défaut selectionner des elements à partir d'une base sqlite
    Bonjour,
    j'ai créer une méthode qui permet de parcourir les éléments d'une colonne,mais je veux sélectionner des éléments si par exemple id =2 ..
    voilà mon code :
    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
     
    public ArrayList<String> getCreator() {
    	ArrayList<String> output = new ArrayList<String>();
     
    	String[] colonnesARecup = new String[] { "CREATOR" };
     
    	Cursor cursorResults = bdd.query(TABLE_COLLECTOR, colonnesARecup, null,
    			null, null, null, "ID", null);
    	if (null != cursorResults) {
    		if (cursorResults.moveToFirst()) {
    			do {
    				int columnIdxNom = cursorResults.getColumnIndex("CREATOR");
     
    				String nomDb = cursorResults.getString(columnIdxNom);
     
    				output.add(nomDb);
    			} while (cursorResults.moveToNext());
    		} // end§if
    	}
    merci

  2. #2
    Expert éminent

    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
    Points : 9 149
    Points
    9 149
    Par défaut
    Bonjour,

    Pour sélectionner un item dans un Adapter

    public abstract void setSelection (int position)

    Since: API Level 1
    Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overriden super method first.
    Parameters

    position Index (starting at 0) of the data item to be selected.
    http://developer.android.com/referen...Selection(int)

  3. #3
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2009
    Messages : 135
    Points : 110
    Points
    110
    Par défaut
    Non,c'est pas ça
    je veux récupérer à partir du base des informations avec une condition (exemple select a from tab where id=1)

  4. #4
    Expert éminent

    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
    Points : 9 149
    Points
    9 149
    Par défaut
    Oups , pas compris la question

    via la fonction query que tu utilises tu peux le faire directement, il te suffit juste de rentrer ta condition.

    http://developer.android.com/referen...a.lang.String)

    public Cursor query (String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit)

    Since: API Level 1
    Query the given table, returning a Cursor over the result set.
    Parameters

    table The table name to compile the query against.
    columns A list of which columns to return. Passing null will return all columns, which is discouraged to prevent reading data from storage that isn't going to be used.
    selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given table.
    selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
    groupBy A filter declaring how to group rows, formatted as an SQL GROUP BY clause (excluding the GROUP BY itself). Passing null will cause the rows to not be grouped.
    having A filter declare which row groups to include in the cursor, if row grouping is being used, formatted as an SQL HAVING clause (excluding the HAVING itself). Passing null will cause all row groups to be included, and is required when row grouping is not being used.
    orderBy How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered.
    limit Limits the number of rows returned by the query, formatted as LIMIT clause. Passing null denotes no LIMIT clause.
    Returns

    A Cursor object, which is positioned before the first entry. Note that Cursors are not synchronized, see the documentation for more details.
    See Also

    Cursor

  5. #5
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2009
    Messages : 135
    Points : 110
    Points
    110
    Par défaut
    est ce que je peux utiliser ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    p_query = "SELECT CREATOR FROM INFO_COLLECTOR WHERE IDCOL=1" ;
    mDb.rawQuery( p_query, null );

  6. #6
    Expert éminent

    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
    Points : 9 149
    Points
    9 149
    Par défaut
    est ce que je peux utiliser ça:
    Oui, cela marche également.

  7. #7
    Membre régulier
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    135
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations forums :
    Inscription : Mars 2009
    Messages : 135
    Points : 110
    Points
    110
    Par défaut
    oui ça marche ,merci

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

Discussions similaires

  1. Réponses: 3
    Dernier message: 22/03/2013, 14h08
  2. [MySQL] récupérer des images à partir d'une base de données mysql
    Par j_esti dans le forum PHP & Base de données
    Réponses: 11
    Dernier message: 21/04/2011, 13h34
  3. Réponses: 9
    Dernier message: 11/10/2010, 18h29
  4. Réponses: 1
    Dernier message: 07/06/2006, 14h06
  5. [FLASH 8] Afficher des images à partir d'une base de données
    Par developpeur_mehdi dans le forum Flash
    Réponses: 9
    Dernier message: 15/03/2006, 10h43

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