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 :

Sections sous android


Sujet :

Android

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    162
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 162
    Par défaut Sections sous android
    Bonjour,

    Je voudrais savoir comment on peut créer des sections sous android. J'ai mis en pièce jointe un écran avec deux sections différentes:
    - Main configuration
    - Account management

    Comment faire pour pouvoir créer ce genre de sections afin éventuellement d'avoir une liste dans une section et dans l'autre des cases à cocher par exemple.

    Je vous remercie de votre aide

    A+
    Fichiers attachés Fichiers attachés

  2. #2
    Membre expérimenté
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2005
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2005
    Messages : 103
    Par défaut
    Bonjour,

    La copie d'écran représente une activité de préférence. Il faut que ton activité étende "PreferenceActivity" (http://developer.android.com/referen...eActivity.html) et réaliser un fichier XML de préférence.

    Par contre pour faire une liste (au sens ListView), il faut partir sur un layout dont les sections sont un TextView avec en background un drawable (image ou xml).

    Exemple de TextView :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    <TextView android:id="@+id/section_1" android:layout_width="fill_parent"
    	  android:layout_height="wrap_content" android:gravity="center" android:text="Section 1"
    	  style="?android:attr/listSeparatorTextViewStyle" />

  3. #3
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    162
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 162
    Par défaut
    Bonjour,

    Je vous remercie. En fait, je sais qu'une section est une textview avec avec une propriété style ajouté dans le xml. Par contre, j'aimerais savoir si vous pouvez m'indiquer comment faire une section directement dans le code java sans passer par le xml. Ok, je crée un textview mais ensuite comment ajouté la ligne:
    style="?android:attr/listSeparatorTextViewStyle"
    présent dans le xml.

    En effet, je cherche à faire ça car je n'ai pas trouvé l'équivalent xml du code se trouvant dans l'api demos dans le site http://developer.android.com qui correspond aux listadapter collapsed:

    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
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
     
    /*
     * Copyright (C) 2007 The Android Open Source Project
     *
     * 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
     *
     *      http://www.apache.org/licenses/LICENSE-2.0
     *
     * 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.
     */
     
    package com.example.android.apis.view;
     
    import android.app.ListActivity;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.TextView;
     
     
    /**
     * A list view example where the 
     * data comes from a custom
     * ListAdapter
     */
    public class List6 extends ListActivity 
    {
     
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
     
            // Use our own list adapter
            setListAdapter(new SpeechListAdapter(this));
        }
     
     
        @Override
        protected void onListItemClick(ListView l, View v, int position, long id) 
        {    
           ((SpeechListAdapter)getListAdapter()).toggle(position);
        }
     
        /**
         * A sample ListAdapter that presents content
         * from arrays of speeches and text.
         *
         */
        private class SpeechListAdapter extends BaseAdapter {
            public SpeechListAdapter(Context context)
            {
                mContext = context;
            }
     
     
            /**
             * The number of items in the list is determined by the number of speeches
             * in our array.
             * 
             * @see android.widget.ListAdapter#getCount()
             */
            public int getCount() {
                return mTitles.length;
            }
     
            /**
             * Since the data comes from an array, just returning
             * the index is sufficent to get at the data. If we
             * were using a more complex data structure, we
             * would return whatever object represents one 
             * row in the list.
             * 
             * @see android.widget.ListAdapter#getItem(int)
             */
            public Object getItem(int position) {
                return position;
            }
     
            /**
             * Use the array index as a unique id.
             * @see android.widget.ListAdapter#getItemId(int)
             */
            public long getItemId(int position) {
                return position;
            }
     
            /**
             * Make a SpeechView to hold each row.
             * @see android.widget.ListAdapter#getView(int, android.view.View, android.view.ViewGroup)
             */
            public View getView(int position, View convertView, ViewGroup parent) {
                SpeechView sv;
                if (convertView == null) {
                    sv = new SpeechView(mContext, mTitles[position], mDialogue[position], mExpanded[position]);
                } else {
                    sv = (SpeechView)convertView;
                    sv.setTitle(mTitles[position]);
                    sv.setDialogue(mDialogue[position]);
                    sv.setExpanded(mExpanded[position]);
                }
     
                return sv;
            }
     
            public void toggle(int position) {
                mExpanded[position] = !mExpanded[position];
                notifyDataSetChanged();
            }
     
            /**
             * Remember our context so we can use it when constructing views.
             */
            private Context mContext;
     
            /**
             * Our data, part 1.
             */
            private String[] mTitles = 
            {
                    "Henry IV (1)",   
                    "Henry V",
                    "Henry VIII",       
                    "Richard II",
                    "Richard III",
                    "Merchant of Venice",  
                    "Othello",
                    "King Lear"
            };
     
            /**
             * Our data, part 2.
             */
            private String[] mDialogue = 
            {
                    "So shaken as we are, so wan with care," +
                    "Find we a time for frighted peace to pant," +
                    "And breathe short-winded accents of new broils" +
                    "To be commenced in strands afar remote." +
                    "No more the thirsty entrance of this soil" +
                    "Shall daub her lips with her own children's blood;" +
                    "Nor more shall trenching war channel her fields," +
                    "Nor bruise her flowerets with the armed hoofs" +
                    "Of hostile paces: those opposed eyes," +
                    "Which, like the meteors of a troubled heaven," +
                    "All of one nature, of one substance bred," +
                    "Did lately meet in the intestine shock" +
                    "And furious close of civil butchery" +
                    "Shall now, in mutual well-beseeming ranks," +
                    "March all one way and be no more opposed" +
                    "Against acquaintance, kindred and allies:" +
                    "The edge of war, like an ill-sheathed knife," +
                    "No more shall cut his master. Therefore, friends," +
                    "As far as to the sepulchre of Christ," +
                    "Whose soldier now, under whose blessed cross" +
                    "We are impressed and engaged to fight," +
                    "Forthwith a power of English shall we levy;" +
                    "Whose arms were moulded in their mothers' womb" +
                    "To chase these pagans in those holy fields" +
                    "Over whose acres walk'd those blessed feet" +
                    "Which fourteen hundred years ago were nail'd" +
                    "For our advantage on the bitter cross." +
                    "But this our purpose now is twelve month old," +
                    "And bootless 'tis to tell you we will go:" +
                    "Therefore we meet not now. Then let me hear" +
                    "Of you, my gentle cousin Westmoreland," +
                    "What yesternight our council did decree" +
                    "In forwarding this dear expedience.",
     
                    "Hear him but reason in divinity," + 
                    "And all-admiring with an inward wish" + 
                    "You would desire the king were made a prelate:" + 
                    "Hear him debate of commonwealth affairs," + 
                    "You would say it hath been all in all his study:" + 
                    "List his discourse of war, and you shall hear" + 
                    "A fearful battle render'd you in music:" + 
                    "Turn him to any cause of policy," + 
                    "The Gordian knot of it he will unloose," + 
                    "Familiar as his garter: that, when he speaks," + 
                    "The air, a charter'd libertine, is still," + 
                    "And the mute wonder lurketh in men's ears," + 
                    "To steal his sweet and honey'd sentences;" + 
                    "So that the art and practic part of life" + 
                    "Must be the mistress to this theoric:" + 
                    "Which is a wonder how his grace should glean it," + 
                    "Since his addiction was to courses vain," + 
                    "His companies unletter'd, rude and shallow," + 
                    "His hours fill'd up with riots, banquets, sports," + 
                    "And never noted in him any study," + 
                    "Any retirement, any sequestration" + 
                    "From open haunts and popularity.",
     
                    "I come no more to make you laugh: things now," +
                    "That bear a weighty and a serious brow," +
                    "Sad, high, and working, full of state and woe," +
                    "Such noble scenes as draw the eye to flow," +
                    "We now present. Those that can pity, here" +
                    "May, if they think it well, let fall a tear;" +
                    "The subject will deserve it. Such as give" +
                    "Their money out of hope they may believe," +
                    "May here find truth too. Those that come to see" +
                    "Only a show or two, and so agree" +
                    "The play may pass, if they be still and willing," +
                    "I'll undertake may see away their shilling" +
                    "Richly in two short hours. Only they" +
                    "That come to hear a merry bawdy play," +
                    "A noise of targets, or to see a fellow" +
                    "In a long motley coat guarded with yellow," +
                    "Will be deceived; for, gentle hearers, know," +
                    "To rank our chosen truth with such a show" +
                    "As fool and fight is, beside forfeiting" +
                    "Our own brains, and the opinion that we bring," +
                    "To make that only true we now intend," +
                    "Will leave us never an understanding friend." +
                    "Therefore, for goodness' sake, and as you are known" +
                    "The first and happiest hearers of the town," +
                    "Be sad, as we would make ye: think ye see" +
                    "The very persons of our noble story" +
                    "As they were living; think you see them great," +
                    "And follow'd with the general throng and sweat" +
                    "Of thousand friends; then in a moment, see" +
                    "How soon this mightiness meets misery:" +
                    "And, if you can be merry then, I'll say" +
                    "A man may weep upon his wedding-day.",
     
                    "First, heaven be the record to my speech!" + 
                    "In the devotion of a subject's love," + 
                    "Tendering the precious safety of my prince," + 
                    "And free from other misbegotten hate," + 
                    "Come I appellant to this princely presence." + 
                    "Now, Thomas Mowbray, do I turn to thee," + 
                    "And mark my greeting well; for what I speak" + 
                    "My body shall make good upon this earth," + 
                    "Or my divine soul answer it in heaven." + 
                    "Thou art a traitor and a miscreant," + 
                    "Too good to be so and too bad to live," + 
                    "Since the more fair and crystal is the sky," + 
                    "The uglier seem the clouds that in it fly." + 
                    "Once more, the more to aggravate the note," + 
                    "With a foul traitor's name stuff I thy throat;" + 
                    "And wish, so please my sovereign, ere I move," + 
                    "What my tongue speaks my right drawn sword may prove.",
     
                    "Now is the winter of our discontent" + 
                    "Made glorious summer by this sun of York;" + 
                    "And all the clouds that lour'd upon our house" + 
                    "In the deep bosom of the ocean buried." + 
                    "Now are our brows bound with victorious wreaths;" + 
                    "Our bruised arms hung up for monuments;" + 
                    "Our stern alarums changed to merry meetings," + 
                    "Our dreadful marches to delightful measures." + 
                    "Grim-visaged war hath smooth'd his wrinkled front;" + 
                    "And now, instead of mounting barded steeds" + 
                    "To fright the souls of fearful adversaries," + 
                    "He capers nimbly in a lady's chamber" + 
                    "To the lascivious pleasing of a lute." + 
                    "But I, that am not shaped for sportive tricks," + 
                    "Nor made to court an amorous looking-glass;" + 
                    "I, that am rudely stamp'd, and want love's majesty" + 
                    "To strut before a wanton ambling nymph;" + 
                    "I, that am curtail'd of this fair proportion," + 
                    "Cheated of feature by dissembling nature," + 
                    "Deformed, unfinish'd, sent before my time" + 
                    "Into this breathing world, scarce half made up," + 
                    "And that so lamely and unfashionable" + 
                    "That dogs bark at me as I halt by them;" + 
                    "Why, I, in this weak piping time of peace," + 
                    "Have no delight to pass away the time," + 
                    "Unless to spy my shadow in the sun" + 
                    "And descant on mine own deformity:" + 
                    "And therefore, since I cannot prove a lover," + 
                    "To entertain these fair well-spoken days," + 
                    "I am determined to prove a villain" + 
                    "And hate the idle pleasures of these days." + 
                    "Plots have I laid, inductions dangerous," + 
                    "By drunken prophecies, libels and dreams," + 
                    "To set my brother Clarence and the king" + 
                    "In deadly hate the one against the other:" + 
                    "And if King Edward be as true and just" + 
                    "As I am subtle, false and treacherous," + 
                    "This day should Clarence closely be mew'd up," + 
                    "About a prophecy, which says that 'G'" + 
                    "Of Edward's heirs the murderer shall be." + 
                    "Dive, thoughts, down to my soul: here" + 
                    "Clarence comes.",
     
                    "To bait fish withal: if it will feed nothing else," + 
                    "it will feed my revenge. He hath disgraced me, and" + 
                    "hindered me half a million; laughed at my losses," + 
                    "mocked at my gains, scorned my nation, thwarted my" + 
                    "bargains, cooled my friends, heated mine" + 
                    "enemies; and what's his reason? I am a Jew. Hath" + 
                    "not a Jew eyes? hath not a Jew hands, organs," + 
                    "dimensions, senses, affections, passions? fed with" + 
                    "the same food, hurt with the same weapons, subject" + 
                    "to the same diseases, healed by the same means," + 
                    "warmed and cooled by the same winter and summer, as" + 
                    "a Christian is? If you prick us, do we not bleed?" + 
                    "if you tickle us, do we not laugh? if you poison" + 
                    "us, do we not die? and if you wrong us, shall we not" + 
                    "revenge? If we are like you in the rest, we will" + 
                    "resemble you in that. If a Jew wrong a Christian," + 
                    "what is his humility? Revenge. If a Christian" + 
                    "wrong a Jew, what should his sufferance be by" + 
                    "Christian example? Why, revenge. The villany you" + 
                    "teach me, I will execute, and it shall go hard but I" + 
                    "will better the instruction.",
     
                    "Virtue! a fig! 'tis in ourselves that we are thus" + 
                    "or thus. Our bodies are our gardens, to the which" + 
                    "our wills are gardeners: so that if we will plant" + 
                    "nettles, or sow lettuce, set hyssop and weed up" + 
                    "thyme, supply it with one gender of herbs, or" + 
                    "distract it with many, either to have it sterile" + 
                    "with idleness, or manured with industry, why, the" + 
                    "power and corrigible authority of this lies in our" + 
                    "wills. If the balance of our lives had not one" + 
                    "scale of reason to poise another of sensuality, the" + 
                    "blood and baseness of our natures would conduct us" + 
                    "to most preposterous conclusions: but we have" + 
                    "reason to cool our raging motions, our carnal" + 
                    "stings, our unbitted lusts, whereof I take this that" + 
                    "you call love to be a sect or scion.",
     
                    "Blow, winds, and crack your cheeks! rage! blow!" + 
                    "You cataracts and hurricanoes, spout" + 
                    "Till you have drench'd our steeples, drown'd the cocks!" + 
                    "You sulphurous and thought-executing fires," + 
                    "Vaunt-couriers to oak-cleaving thunderbolts," + 
                    "Singe my white head! And thou, all-shaking thunder," + 
                    "Smite flat the thick rotundity o' the world!" + 
                    "Crack nature's moulds, an germens spill at once," + 
                    "That make ingrateful man!"
            };
     
            /**
             * Our data, part 3.
             */
            private boolean[] mExpanded = 
            {
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false   
            };
        }
     
        /**
         * We will use a SpeechView to display each speech. It's just a LinearLayout
         * with two text fields.
         *
         */
        private class SpeechView extends LinearLayout {
            public SpeechView(Context context, String title, String dialogue, boolean expanded) {
                super(context);
     
                this.setOrientation(VERTICAL);
     
                // Here we build the child views in code. They could also have
                // been specified in an XML file.
     
                mTitle = new TextView(context);
                mTitle.setText(title);
                addView(mTitle, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
     
                mDialogue = new TextView(context);
                mDialogue.setText(dialogue);
                addView(mDialogue, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
     
                mDialogue.setVisibility(expanded ? VISIBLE : GONE);
            }
     
            /**
             * Convenience method to set the title of a SpeechView
             */
            public void setTitle(String title) {
                mTitle.setText(title);
            }
     
            /**
             * Convenience method to set the dialogue of a SpeechView
             */
            public void setDialogue(String words) {
                mDialogue.setText(words);
            }
     
            /**
             * Convenience method to expand or hide the dialogue
             */
            public void setExpanded(boolean expanded) {
                mDialogue.setVisibility(expanded ? VISIBLE : GONE);
            }
     
            private TextView mTitle;
            private TextView mDialogue;
        }
    }


    Je vous remercie par avance,

    A+

  4. #4
    Membre expérimenté
    Homme Profil pro
    Développeur Java
    Inscrit en
    Avril 2005
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Avril 2005
    Messages : 103
    Par défaut
    Bonjour,

    Le 3eme argument du constructeur d'un TextView prend l'id d'un styleable. Sinon il faudrait regarder du coté de obtainStyledAttributes.


    Sinon pour le listadapter collapsed, je vois pas trop le problème ? Le xml layout de l'item c'est un linearlayout en vertical avec deux textview. Ensuite il faudrait gérer dans le getView le setVisibility du mDialogue.

Discussions similaires

  1. Nokia prépare un netbook sous Android
    Par Kerod dans le forum Mobiles
    Réponses: 3
    Dernier message: 01/07/2009, 09h53
  2. Nokia prépare un netbook sous Android
    Par Kerod dans le forum Actualités
    Réponses: 0
    Dernier message: 30/06/2009, 15h56
  3. Nokia prépare un netbook sous Android
    Par Kerod dans le forum Android
    Réponses: 0
    Dernier message: 30/06/2009, 15h56
  4. La 2D sous Android
    Par Julien Bodin dans le forum Android
    Réponses: 7
    Dernier message: 18/03/2009, 21h04
  5. Section sous Word
    Par digabriel dans le forum VBA Word
    Réponses: 1
    Dernier message: 14/08/2005, 07h22

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