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 :

personnaliser une liste qui fait appel aux données dans une base de donnée mysql


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Femme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 36
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Janvier 2016
    Messages : 40
    Par défaut personnaliser une liste qui fait appel aux données dans une base de donnée mysql
    bonjour;
    je travaille sur une application qui affiche les données d'une base de donnée mysql dans une liste et je veux personnaliser ma liste en lui mettant un peu de design
    comment on peut affecter un fichier xml a une liste qui ramène les données d'une base de donnée mysql?
    voici 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
    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
     
     
     
    public class maclasse extends ActionBarActivity {
     
    	ArrayList<String> listItems=new ArrayList<String>();
        ArrayAdapter<String> adapter;
        HttpURLConnection urlConnection = null;
        ListView spp;
     Button button3;
     
     
       protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_societe);
     spp=(ListView)findViewById(R.id.spinner66);
     
     
     
     
      adapter=new ArrayAdapter<String>(this,R.layout.spin_layout,R.id.text,listItems);
         spp.setAdapter(adapter);
     
         button3=(Button)findViewById(R.id.button10);
     
         spp.setOnItemClickListener(new OnItemClickListener(){
     
       @Override
    	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
     
    	   int position = arg2;
    		 String  message2    = (String) spp.getItemAtPosition(position);
     
    		 Intent intent = new Intent();
    	     int id=intent.getIntExtra("id", 1); 
    	        intent.putExtra("MESSAGE",message2);
     
    	        setResult(2,intent);
     
     
    	        finish();  	
     
    	}
         });
     
     
        }  
     
      public void onStart(){
         super.onStart();
         BackTask bt=new BackTask();
         bt.execute();
      }
      private class BackTask extends AsyncTask<Void,Void,Void> {
         ArrayList<String> list;
         protected void onPreExecute(){
           super.onPreExecute();
           list=new ArrayList<String>();
         }
     
     
         protected Void doInBackground(Void...params){
           InputStream is=null;
           String result="";
           try{
     
     URL url = new URL("http://nom_de_domaine/fichier");
         urlConnection = (HttpURLConnection) url.openConnection();
         urlConnection.connect();
         is = urlConnection.getInputStream();
     
     
            }catch(IOException e){
              e.printStackTrace();
           }
     
     
           try{
              BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"));           
              String line = null;
              while ((line = reader.readLine()) != null) {
                result+=line;
              }
              is.close();
              //result=sb.toString();
           }catch(Exception e){
              e.printStackTrace();
           }
           // parse json data
           try{
              JSONArray jArray =new JSONArray(result);
              for(int i=0;i<jArray.length();i++){
                 JSONObject jsonObject=jArray.getJSONObject(i);
                 // add interviewee name to arraylist
                 list.add(jsonObject.getString("nom"));
              }
           }  
     
           catch(JSONException e){
              e.printStackTrace();
           }
           return null;
         }
         protected void onPostExecute(Void result){
           listItems.addAll(list);
           adapter.notifyDataSetChanged();
         }
      }
     
    }
    bonne journnée

  2. #2
    Membre chevronné

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2014
    Messages
    262
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : Burkina Faso

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Finance

    Informations forums :
    Inscription : Août 2014
    Messages : 262
    Par défaut
    Citation Envoyé par soussou angel Voir le message
    bonjour;
    je travaille sur une application qui affiche les données d'une base de donnée mysql dans une liste et je veux personnaliser ma liste en lui mettant un peu de design
    comment on peut affecter un fichier xml a une liste qui ramène les données d'une base de donnée mysql?
    ...
    Bonjour ma grande, je ne sais pas, en quoi consiste la personnalisation de ta liste ?
    Est-ce la vue qui permet d'afficher chaque élément de la liste que tu veux personnaliser ou
    est-ce l'apparence même de la liste tout entière ?

    Sinon, il est possible de décider de comment afficher les différents items de la liste. Pour ton cas,
    Etant donné que tu affiche une seule ligne de texte, tu peux le faire à partir du constructeur même :

    adapter=new ArrayAdapter<String>(this,R.layout.spin_layout,R.id.text,listItems);

    le premier paramètre représente ton fichier xml,
    le deuxième paramètre représente l'identifiant du TextView devant recevoir les données
    le troisième c'est l'ensemble des données provenant de la base de données

    tu peux aussi créer une classe qui dérive de ArrayAdapter<String> et tu surcharge la méthode
    public View getView(int position, View convertView, ViewGroup parent).
    Cette méthode est sensée renvoyer à tout moment la vue devant être affichée pour chaque élément de la liste.

    J'espère avoir été util, sinon fais moi savoir !

    ___salut !

  3. #3
    Membre Expert
    Avatar de MathiasSeguy
    Homme Profil pro
    Fondateur Android2EE - Formation Expertise Android
    Inscrit en
    Avril 2011
    Messages
    185
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Fondateur Android2EE - Formation Expertise Android
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2011
    Messages : 185
    Billets dans le blog
    6
    Par défaut
    Bonjour
    Je vais te dire qu'il faut monter un peu en compétence
    Tout d'abord j'ai pas bien vu ta base de données, tu fais un appel réseau, dans une AsyncTask, dans l'activité.
    Et ça c'est le mal: Que se passe-t-il si tu n'as pas de réseau ? que se passe-t-il si un appel téléphonique interrompt ton activité ? Que se passe-t-il si ton utilisateur retourne son téléphone ? Combien de fuite mémoire je génère si je retourne trois fois de suite mon téléphone ? (tu peux lire ça http://mathias-seguy.developpez.com/...ites-memoires/ pour mieux comprendre de quoi je parle)
    Le mieux, c'est de sortir ton appel réseau de là, de le faire dans une classe à part et de retenir les informations renvoyées dans la base de données SQlite et de mettre un petit système de cache... bon mais c'est pas ta question.
    Pour ta question, le mieux est de te faire un MonArrayAdapter extends ArrayAdapter, regardes ce post pour mieux comprendre :http://www.developpez.net/forums/d13...-arrayadapter/
    Pour info, utilises toujours la ConvertView fournie en paramètre de getView (dans l'arrayAdapter) sinon tu fais du mal au système, aux chats et aux bisounours, c'est important de ne pas leur faire de mal:
    Un exemple complet mais un peu complexe du coup
    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
     
    package com.android2ee.formation.mai.mmxiii.premiertp;
     
    import java.util.List;
     
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.ArrayAdapter;
    import android.widget.TextView;
     
    /**
     * @author Mathias Seguy (Android2EE)
     * @goals
     *        This class aims to:
     *        <ul>
     *        <li></li>
     *        </ul>
     */
    public class HumanAdapter extends ArrayAdapter<Human> implements HumanAdapterCallBack {
     
    	LayoutInflater inflater;
     
    	HumanAdapterCallBack callBack;
    	/**
             * @param context
             * @param resource
             * @param textViewResourceId
             * @param objects
             */
    	public HumanAdapter(Context context, List<Human> objects) {
    		super(context, R.layout.item, objects);
    		inflater = LayoutInflater.from(getContext());
    		callBack=(HumanAdapterCallBack)context;
    	}
     
    	//Avoid using temp variable as method's variable
    	private static Human hum;
    	private static View myview;
    	private static ViewHolder viewHolder;
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
    	 */
    	@Override
    	public View getView(int position, View convertView, ViewGroup parent) {
    		 hum = getItem(position);
    		 myview = convertView;
    		if (null == myview) {
    			if(getItemViewType(position)==0) {
    				myview = inflater.inflate(R.layout.item, null);
     
    			}else {
    				myview = inflater.inflate(R.layout.item_odd, null);
    			}
    			viewHolder=new ViewHolder(myview);
    			myview.setTag(viewHolder);
    		}else {
    			viewHolder=(ViewHolder) myview.getTag();
    		}
    		viewHolder.getTxvMessage().setText(hum.getMessage());
    		viewHolder.getTxvName().setText(hum.getName());
     
    		viewHolder.getTxvMessage().setOnClickListener(new MyOnClickListener(position, this));
    		viewHolder.getTxvName().setOnClickListener(new MyOnClickListener(position, this));
    		return myview;
    	}
     
     
    	/**
             * @param position
             */
    	public void itemSelected(int position) {
    		callBack.itemSelected(position);
    	}
    	/******************************************************************************************/
    	/** Managing differents view **************************************************************************/
    	/******************************************************************************************/
     
    	/******************************************************************************************/
    	/** Managing the odd/even lines **************************************************************************/
    	/******************************************************************************************/
     
    	@Override
    	public int getViewTypeCount() {
    		// return the number of type managed by the list view:
    		// We have two types, one for the even line, the other for the odd lines
    		return 2;
    	}
     
    	@Override
    	public int getItemViewType(int position) {
    		// return the type of the element to be displayed at position position
    		// We have two types, one for the even line, the other for the odd lines
    		return position % 2;
    	}
     
    	public static class MyOnClickListener implements OnClickListener{
     
    		int position;
    		HumanAdapterCallBack hum;
    		/**
                     * @param position
                     */
    		private MyOnClickListener(int position,HumanAdapterCallBack hum) {
    			super();
    			this.position = position;
    			this.hum=hum;
    		}
     
    		/* (non-Javadoc)
    		 * @see android.view.View.OnClickListener#onClick(android.view.View)
    		 */
    		@Override
    		public void onClick(View v) {
    			hum.itemSelected(position);
    		}
     
    	}
     
    	/******************************************************************************************/
    	/** ViewHolder **************************************************************************/
    	/******************************************************************************************/
     
     
    	public static class ViewHolder {
    		View boundView;
    		TextView txvName;
    		TextView txvMessage;
     
    		/**
                     * @param boundView
                     */
    		private ViewHolder(View boundView) {
    			super();
    			this.boundView = boundView;
    		}
     
    		/**
                     * @return the txvName
                     */
    		public final TextView getTxvName() {
    			if (null == txvName) {
    				txvName = (TextView) boundView.findViewById(R.id.nom);
    			}
    			return txvName;
    		}
     
    		/**
                     * @param txvName
                     *            the txvName to set
                     */
    		public final void setTxvName(TextView txvName) {
    			this.txvName = txvName;
    		}
     
    		/**
                     * @return the txvMessage
                     */
    		public final TextView getTxvMessage() {
    			if (null == txvMessage) {
    				txvMessage = (TextView) boundView.findViewById(R.id.message);
    			}
    			return txvMessage;
    		}
     
    		/**
                     * @param txvMessage
                     *            the txvMessage to set
                     */
    		public final void setTxvMessage(TextView txvMessage) {
    			this.txvMessage = txvMessage;
    		}
     
    	}
     
    }
    et l'activité associée:
    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
    package com.android2ee.formation.mai.mmxiii.premiertp;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.Dialog;
    import android.content.DialogInterface;
    import android.content.DialogInterface.OnClickListener;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ListView;
    import android.widget.Toast;
     
    /**
     * @author Mathias Seguy (Android2EE)
     * @goals
     *        This class aims to be the first app
     */
    public class MainActivity extends Activity implements HumanAdapterCallBack {
    	/**
             * Edt Message
             */
    	EditText edtMessage;
    	/**
             * button Add
             */
    	Button btnAdd;
    	/**
             * The listView
             */
    	ListView lstMessage;
     
    	/**
             * The items to display
             */
    	List<Human> items;
    	/**
             * The arrayAdpter that is bound to the ListView
             */
    	HumanAdapter arrayAdapter;
    	/**
             * The AlertDialog constant
             */
    	private final static int ALERT_DIALOG1 = 1000001;
     
    	/******************************************************************************************/
    	/** Managing life cycle **************************************************************************/
    	/******************************************************************************************/
     
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    		// Les findViewById
    		instantiateView();
    		// ListView initialization
    		initializeListView();
    		// Add listener on ListView and button
    		addListeners();
    	}
     
    	/******************************************************************************************/
    	/** CreateDialog **************************************************************************/
    	/******************************************************************************************/
    	/*
    	 * (non-Javadoc)
    	 * 
    	 * @see android.app.Activity#onCreateDialog(int)
    	 */
    	@Override
    	protected Dialog onCreateDialog(int id) {
    		Dialog dialog = null;
    		switch (id) {
    		case ALERT_DIALOG1:
    			dialog = createFirstDialog();
    			break;
    		default:
    			break;
    		}
    		return dialog;
    	}
     
    	private Dialog createFirstDialog() {
    		AlertDialog.Builder builder = new AlertDialog.Builder(this);
    		builder.setMessage("You should externalyze that string");
    		builder.setTitle("Title (hard coded)");
    		builder.setPositiveButton("Yes", new OnClickListener() {
    			@Override
    			public void onClick(DialogInterface dialog, int which) {
    				dialogDismiss(Activity.RESULT_OK);
     
    			}
    		});
    		builder.setNegativeButton("No", new OnClickListener() {
    			@Override
    			public void onClick(DialogInterface dialog, int which) {
    				dialogDismiss(RESULT_NOK);
     
    			}
    		});
    		builder.setNeutralButton("?o?", new OnClickListener() {
    			@Override
    			public void onClick(DialogInterface dialog, int which) {
    				dialogDismiss(Activity.RESULT_CANCELED);
     
    			}
    		});
    		return builder.create();
    	}
     
    	private static final int RESULT_NOK = -10010010;
     
    	/**
             * When the dialog closes this method is called
             * 
             * @param state
             */
    	private void dialogDismiss(int state) {
    		String result;
    		switch (state) {
    		case RESULT_NOK:
    			result="nok";
    			break;
    		case RESULT_OK:
    			result="ok";
    			break;
    		case RESULT_CANCELED:
    			result="cancel";
    			break;
    		default:
    			result="unde";
    			break;
    		}
    		Toast.makeText(this, "The result is:! "+result, Toast.LENGTH_SHORT).show();
    	}
     
    	/******************************************************************************************/
    	/** Instantiate Activity **************************************************************************/
    	/******************************************************************************************/
     
    	/**
             * 
             */
    	private void initializeListView() {
    		// Instanciate the listView
    		items = new ArrayList<Human>();
    		Human current;
    		for (int i = 0; i < 1000; i++) {
    			current = new Human(" message " + i);
    			items.add(current);
    		}
    		arrayAdapter = new HumanAdapter(this, items);
     
    		lstMessage.setAdapter(arrayAdapter);
    	}
     
    	/**
             * 
             */
    	private void addListeners() {
    		lstMessage.setOnItemClickListener(new OnItemClickListener() {
    			@Override
    			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    				itemSelected(position);
    			}
    		});
    		// Add listener
    		btnAdd.setOnClickListener(new View.OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				btnAddClicked();
    			}
    		});
    	}
     
    	/**
             * 
             */
    	private void instantiateView() {
    		edtMessage = (EditText) findViewById(R.id.edt_message);
    		btnAdd = (Button) findViewById(R.id.btn_add);
    		lstMessage = (ListView) findViewById(R.id.lsv_messages);
    		Log.e(this.getClass().getSimpleName(),"My log message");
    	}
     
    	/******************************************************************************************/
    	/** Managing selection **************************************************************************/
    	/******************************************************************************************/
     
    	/* (non-Javadoc)
    	 * @see com.android2ee.formation.mai.mmxiii.premiertp.HumanAdapterCallBack#itemSelected(int)
    	 */
    	@Override
    	public void itemSelected(int position) {
    		Human human = arrayAdapter.getItem(position);
    		edtMessage.setText(human.getMessage());
    	}
     
    	/**
             * Called when a click is done on the btnAdd
             */
    	private void btnAddClicked() {
    		// Read EditText
    		String str = edtMessage.getText().toString();
    		Human toto = new Human(str);
    		// Add the string to the txvMessages
    		arrayAdapter.add(toto);
    		// Or
    		// items.add(str);
    		// arrayAdapter.notifyDataSetChanged();
    		// and flush the editText
    		edtMessage.setText("");
    		showDialog(ALERT_DIALOG1);
    	}
    }
    Bon et du coup, les classes Human
    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
     
    package com.android2ee.formation.mai.mmxiii.premiertp;
     
    /**
     * @author Mathias Seguy (Android2EE)
     * @goals
     *        This class aims to:
     *        <ul>
     *        <li></li>
     *        </ul>
     */
    public class Human {
    	/**
             * 
             */
    	private String name = "Toto";
    	/**
             * 
             */
    	private String message;
     
    	/**
             * 
             */
    	public Human(String message) {
    		this.message = message;
    	}
     
    	/**
             * @return the name
             */
    	public final String getName() {
    		if (null == name) {
    			name = new String();
    		}
    		return name;
    	}
     
    	/**
             * @param name
             *            the name to set
             */
    	public final void setName(String name) {
    		this.name = name;
    	}
     
    	/**
             * @return the message
             */
    	public final String getMessage() {
    		if (null == message) {
    			message = new String();
    		}
    		return message;
    	}
     
    	/**
             * @param message
             *            the message to set
             */
    	public final void setMessage(String message) {
    		this.message = message;
    	}
     
    }
    et HumanCallBack
    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
     
    package com.android2ee.formation.mai.mmxiii.premiertp;
     
    /**
     * @author Mathias Seguy (Android2EE)
     * @goals
     * This class aims to:
     * <ul><li></li></ul>
     */
    public interface HumanAdapterCallBack {
     
    	/**
             * @param position
             */
    	public abstract void itemSelected(int position);
     
    }
    et les fichiers de layout
    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
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity" >
     
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="@string/hello_world"
            android:background="@drawable/translucent_selector" 
            style="@style/styleTitle"/>
     
        <EditText
            android:id="@+id/edt_message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/edt_dosomething"
            android:inputType="text|textCapSentences"
            style="@style/styleEdt"/>
     
        <Button
            android:id="@+id/btn_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/btn_add"
            android:background="@drawable/button"/>
     
        <ListView
            android:id="@+id/lsv_messages"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
     
    </LinearLayout>
    et celui pour les items de la liste:
    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
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        tools:context=".MainActivity"
        android:background="@drawable/list_item"
        >
     
        <TextView
            android:id="@+id/nom"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_weight="1.0"
            android:background="@drawable/translucent_selector"
            style="@style/styleTxv" />
     
        <TextView
            android:id="@+id/message"
            android:textIsSelectable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2.0"
            android:background="@drawable/translucent_selector"
            android:gravity="center"
            style="@style/styleTxv"/>
     
    </LinearLayout>

Discussions similaires

  1. erreur récupération des données depuis base de données dans une liste
    Par amintoraa dans le forum Développement Web en Java
    Réponses: 3
    Dernier message: 25/04/2014, 23h41
  2. Réponses: 22
    Dernier message: 13/09/2013, 14h20
  3. Réponses: 2
    Dernier message: 14/05/2011, 01h08
  4. Afficher le contenue d'une base de données dans une liste
    Par fdoncev dans le forum SharePoint
    Réponses: 3
    Dernier message: 16/07/2008, 18h00
  5. Réponses: 7
    Dernier message: 28/06/2007, 11h08

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