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 :

Modifier une TextView dans un Dialog


Sujet :

Composants graphiques Android

  1. #1
    Membre habitué Avatar de cad13
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    247
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 247
    Points : 197
    Points
    197
    Par défaut Modifier une TextView dans un Dialog
    Bonjour,

    Je cherche à afficher un tableau dynamique dans un dialog. J'ai donc créé un layout xml avec la description de mon tableau.

    Voici le début du xml (le reste, c'est la même chose) :
    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
    <?xml version="1.0" encoding="utf-8"?>
     
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
     
        <TableRow>
            <TextView
                android:layout_marginLeft="10dip"
                android:text="Lu" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Ma" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Me" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Je" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Ve" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Sa" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
            <TextView
                android:text="Di" android:typeface="monospace" android:textStyle="bold" android:textSize="20sp"
                android:padding="5dip" />
        </TableRow>
    Dans mon code, j'initialise les TextView :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    TextView d01 = (TextView)findViewById(R.id.x11);
    Ensuite, je souhaite modifier les 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
    View messageView = getLayoutInflater().inflate(R.layout.mois, null, false);
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    d01.setText("01");
    dialog.setIcon(R.drawable.mois);
    dialog.setTitle("   Août 2010");
    dialog.setNeutralButton("Suivant",
    	new DialogInterface.OnClickListener() {
    		public void onClick(DialogInterface dialog, int id) {
    	    	// action 
    		}
    	});
    dialog.setView(messageView);
    dialog.create();
    dialog.show();
    Malheureusement, le programme plante (NullPointerException) au niveau de d01.setText("01");

    N'est-il pas possible de modifier les textview contenues dans un dialog ?
    Christian
    Nexus 1 sous Cyanogen - Acer A500

  2. #2
    Membre habitué Avatar de cad13
    Homme Profil pro
    Inscrit en
    Janvier 2010
    Messages
    247
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 247
    Points : 197
    Points
    197
    Par défaut
    J'ai trouvé comment faire en modifiant le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    AlertDialog.Builder builder;
     
    LayoutInflater inflater = (LayoutInflater)this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.agora_mois, (ViewGroup) findViewById(R.id.layout_root));
     
    TextView text = (TextView) layout.findViewById(R.id.x11);
    text.setText("01");
     
    builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    builder.create();
    builder.show();
    NB : le fait de mettre getApplicationContext à la place de this provoque une exception...
    Christian
    Nexus 1 sous Cyanogen - Acer A500

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

Discussions similaires

  1. Modifier une ligne dans stdout
    Par getupa dans le forum Général Python
    Réponses: 2
    Dernier message: 21/12/2005, 18h18
  2. Modifier une requête dans toutes ces tables...
    Par SnickeursMan dans le forum Requêtes
    Réponses: 6
    Dernier message: 14/12/2005, 13h08
  3. modifier une variable dans un fichier
    Par Guismay dans le forum Langage
    Réponses: 7
    Dernier message: 11/09/2005, 19h46
  4. [C#] Modifier une valeur dans une DataTable
    Par Scorff dans le forum ASP.NET
    Réponses: 2
    Dernier message: 23/05/2005, 10h45
  5. Comment faire pour modifier une ligne dans une DBGrid?
    Par Nico62 dans le forum C++Builder
    Réponses: 6
    Dernier message: 29/03/2005, 12h24

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