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 :

Ajouter des boutons dynamique ?


Sujet :

Composants graphiques Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2013
    Messages : 11
    Par défaut Ajouter des boutons dynamique ?
    Bonjour à tous,

    Après des nombreuses recherches sur internet qui ont été infructueuses, je me permets de vous demander de l'aide.

    En effet, je cherche à ajouter des boutons dynamiquement. Le contenue de ces derniers sont aussi dynamique (avec une base de donnée)

    Merci D'avance.

  2. #2
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    153
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 153
    Par défaut
    Bonjour mhamed22,
    J'ai envie de dire que pour créer des objet dynamiquement (au cours de l'exécution) il faut penser à la généricité. Mais là ton problème n'est pas très claire. Qu'essaies-tu de faire avec tes boutons?
    même le contenue de ces boutons sont dynamique
    qu'entends-tu par contenue du bouton? veux-tu parler du comportement?

  3. #3
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2013
    Messages : 11
    Par défaut
    Merci pour votre réponse ,

    Je veux créer des boutons pour des événements. Par exemple j'ai des boutons

    Even 1 (Titre) --------(quand je clique )----------> description de Even1
    Even 2 (Titre) --------(quand je clique )----------> description de Even2
    Even 3 (Titre) --------(quand je clique )----------> description de Even2
    ......
    ......
    ......


    Comme ce style à peu près :

    Nom : SC20131029-125039.png
Affichages : 335
Taille : 385,0 Ko



    Ces butons s'affichent dynamiquement. Quand j'ai un nouvel événement je crier un nouveau bouton et quand je clique sur un de ces boutons, il m'affiche la description de ce événement dynamiquement.
    Merci .

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Octobre 2009
    Messages
    153
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2009
    Messages : 153
    Par défaut
    Si j'ai bien compris ta préoccupation, Voici une démarche.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
    public class B extends JButton implements ActionListener{
        JLabel lab //label sur lequel apparaitra la descrption de l'évènement
     
        public B(String title, JLabel lab){
             super(title);
             this.lab=lab;
         }
     
        @Override
        public void actionPerformed(ActionEvent e) {
           //place le label sur la partie de la fenetre où tu veux voir afficher la  description de l'évènement.
        }
    }
    tu n'auras plus qu'a instancier ce bouton lorsque surviendra un de tes évènements (Click sur un autre bouton ...)

    fais-le moi savoir si je t'ai mal interprété

  5. #5
    Membre averti
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2013
    Messages : 11
    Par défaut
    Merci pour votre réponse ,

    J'ai trouvé une solution mais avec une ListView et non des Boutons.
    Pouvez vous m'aider pour convertir la listview en bouton s'il vous plait?

    Merci


    Voici le code 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
    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
     
    package com.example.androidhive;
     
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
     
    import org.apache.http.NameValuePair;
    import org.json.JSONArray;
    import org.json.JSONException;
    import org.json.JSONObject;
     
    import android.app.ListActivity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.ListAdapter;
    import android.widget.ListView;
    import android.widget.SimpleAdapter;
    import android.widget.TextView;
     
    public class AllProductsActivity extends ListActivity {
     
    	// Progress Dialog
    	private ProgressDialog pDialog;
     
    	// Creating JSON Parser object
    	JSONParser jParser = new JSONParser();
     
    	ArrayList<HashMap<String, String>> productsList;
     
    	// url to get all products list
    	private static String url_all_products = "http://10.0.2.2/android_connect/get_all_products.php";
     
    	// JSON Node names
    	private static final String TAG_SUCCESS = "success";
    	private static final String TAG_PRODUCTS = "products";
    	private static final String TAG_PID = "pid";
    	private static final String TAG_NAME = "name";
     
    	// products JSONArray
    	JSONArray products = null;
     
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.all_products);
     
    		// Hashmap for ListView
    		productsList = new ArrayList<HashMap<String, String>>();
     
    		// Loading products in Background Thread
    		new LoadAllProducts().execute();
     
    		// Get listview
    		ListView lv = getListView();
     
    		// on seleting single product
    		// launching Edit Product Screen
    		lv.setOnItemClickListener(new OnItemClickListener() {
     
    			@Override
    			public void onItemClick(AdapterView<?> parent, View view,
    					int position, long id) {
    				// getting values from selected ListItem
    				String pid = ((TextView) view.findViewById(R.id.pid)).getText()
    						.toString();
     
    				// Starting new intent
    				Intent in = new Intent(getApplicationContext(),
    						EditProductActivity.class);
    				// sending pid to next activity
    				in.putExtra(TAG_PID, pid);
     
    				// starting new activity and expecting some response back
    				startActivityForResult(in, 100);
    			}
    		});
     
    	}
     
    	// Response from Edit Product Activity
    	@Override
    	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    		super.onActivityResult(requestCode, resultCode, data);
    		// if result code 100
    		if (resultCode == 100) {
    			// if result code 100 is received 
    			// means user edited/deleted product
    			// reload this screen again
    			Intent intent = getIntent();
    			finish();
    			startActivity(intent);
    		}
     
    	}
     
    	/**
             * Background Async Task to Load all product by making HTTP Request
             * */
    	class LoadAllProducts extends AsyncTask<String, String, String> {
     
    		/**
                     * Before starting background thread Show Progress Dialog
                     * */
    		@Override
    		protected void onPreExecute() {
    			super.onPreExecute();
    			pDialog = new ProgressDialog(AllProductsActivity.this);
    			pDialog.setMessage("Loading products. Please wait...");
    			pDialog.setIndeterminate(false);
    			pDialog.setCancelable(false);
    			pDialog.show();
    		}
     
    		/**
                     * getting All products from url
                     * */
    		protected String doInBackground(String... args) {
    			// Building Parameters
    			List<NameValuePair> params = new ArrayList<NameValuePair>();
    			// getting JSON string from URL
    			JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
     
    			// Check your log cat for JSON reponse
    			Log.d("All Products: ", json.toString());
     
    			try {
    				// Checking for SUCCESS TAG
    				int success = json.getInt(TAG_SUCCESS);
     
    				if (success == 1) {
    					// products found
    					// Getting Array of Products
    					products = json.getJSONArray(TAG_PRODUCTS);
     
    					// looping through All Products
    					for (int i = 0; i < products.length(); i++) {
    						JSONObject c = products.getJSONObject(i);
     
    						// Storing each json item in variable
    						String id = c.getString(TAG_PID);
    						String name = c.getString(TAG_NAME);
     
    						// creating new HashMap
    						HashMap<String, String> map = new HashMap<String, String>();
     
    						// adding each child node to HashMap key => value
    						map.put(TAG_PID, id);
    						map.put(TAG_NAME, name);
     
    						// adding HashList to ArrayList
    						productsList.add(map);
    					}
    				} else {
    					// no products found
    					// Launch Add New product Activity
    					Intent i = new Intent(getApplicationContext(),
    							NewProductActivity.class);
    					// Closing all previous activities
    					i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    					startActivity(i);
    				}
    			} catch (JSONException e) {
    				e.printStackTrace();
    			}
     
    			return null;
    		}
     
    		/**
                     * After completing background task Dismiss the progress dialog
                     * **/
    		protected void onPostExecute(String file_url) {
    			// dismiss the dialog after getting all products
    			pDialog.dismiss();
    			// updating UI from Background Thread
    			runOnUiThread(new Runnable() {
    				public void run() {
    					/**
                                             * Updating parsed JSON data into ListView
                                             * */
    					ListAdapter adapter = new SimpleAdapter(
    							AllProductsActivity.this, productsList,
    							R.layout.list_item, new String[] { TAG_PID,
    									TAG_NAME},
    							new int[] { R.id.pid, R.id.name });
    					// updating listview
    					setListAdapter(adapter);
    				}
    			});
     
    		}
     
    	}
    }

Discussions similaires

  1. Réponses: 1
    Dernier message: 19/08/2006, 19h40
  2. Réponses: 1
    Dernier message: 14/08/2006, 09h41
  3. ajouter des boutons à une InputBox
    Par guigui5931 dans le forum Access
    Réponses: 5
    Dernier message: 10/08/2006, 12h18
  4. [FLASH 8] gérer des boutons dynamiquement
    Par gregooo dans le forum Flash
    Réponses: 1
    Dernier message: 04/02/2006, 21h22

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