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 :

Problème affichage ListView (LazyAdapter)


Sujet :

Composants graphiques Android

  1. #1
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Points : 22
    Points
    22
    Par défaut Problème affichage ListView (LazyAdapter)
    Bonjour,

    Je veux afficher une liste de produit avec ses informations (stockées dans une base de données dont l'url de son image qui est elle stockée sur un serveur web)

    J'ai trouvé un tuto sur internet qui utilise ce principe mais les URLs sont en dure dans le programme contrairement à mon cas où j'utilise une liste dynamique.

    Mon problème est que la liste en elle-même n'apparaît même pas dans mon activité et je n'ai aucune erreur dans le log.

    Activité :

    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
    package com.example.test;
     
    public class ListeProduits extends Activity {
     
    	ListView list;
     
                        ....................
     
    	LazyAdapter adapter2;
     
     
    	ArrayList<HashMap<String, String>> listp = new ArrayList<HashMap<String, String>>();
     
    	//URL to get JSON Array
    	private static String url = "http://xxxx.free.fr/xxxxx.php";
     
    	//JSON Node Names 
    	public static final String TAG_PRODUIT = "Produit";
    	public static final String TAG_PRIX = "Prix";
    	public static final String TAG_ENSTOCK = "Quantite";
    	public static final String TAG_DESCRIPTION = "Description";
    	public static final String TAG_RESTANT = "Restant";
    	public static final String TAG_URLIMAGE = "URLimage";
     
     
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.liste_produits);	
     
            new JSONParse().execute();
     
    	    LPProduit = (TextView)findViewById(R.id.LPProduit);
     
                      .....................
     
            listp = new ArrayList<HashMap<String, String>>();
     
        }
     
     
    public class JSONParse extends AsyncTask<String, String, JSONArray> {
        	 private ProgressDialog pDialog;
        	@Override
            protected void onPreExecute() {
                super.onPreExecute();
     
     
                pDialog = new ProgressDialog(ListeProduits.this);
                pDialog.setMessage("Chargement des données ...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(true);
                pDialog.show();
     
        	}
     
        	@Override
            protected JSONArray doInBackground(String... args) {
     
        		JSONParser jParser = new JSONParser();
        		// Getting JSON from URL
        		JSONArray json = jParser.getJSONFromUrl(url);
        		return json;
     
        	}
        	 @Override
             protected void onPostExecute(JSONArray json) {
        		 pDialog.dismiss();
        		 try {
        				// On récupère le tableau JSON de l'URL
     
        				for(int i = 0; i < json.length(); i++){
        				JSONObject c = json.getJSONObject(i);
     
        				// On stocke les valeurs JSON dans une variable
        				produit = c.getString(TAG_PRODUIT);
        				prix = c.getString(TAG_PRIX);
        				dispo = c.getString(TAG_ENSTOCK);
        				description = c.getString(TAG_DESCRIPTION);
        				URLimage = c.getString(TAG_URLIMAGE);
     
        				restant = Integer.parseInt(dispo);
     
     
        				// Adding value HashMap key => value
        				HashMap<String, String> map = new HashMap<String, String>();
     
        				map.put(TAG_PRODUIT, produit);
        				map.put(TAG_PRIX, prix +" euros");
     
        				if(restant == 0) {
        					map.put(TAG_ENSTOCK, "Rupture de stock");
        				}
        				else {
        					map.put(TAG_ENSTOCK, "En Stock");
        				}
     
        				map.put(TAG_DESCRIPTION, description);
     
        				if(restant != 0 && restant < 5) {
        					Restant = "Il ne reste plus que "+restant+" exemplaires";
        					map.put(TAG_RESTANT, Restant);
    	            	}  		            	
        				else {
        					map.put(TAG_RESTANT, "null");
        				}
     
        				map.put(TAG_URLIMAGE, URLimage);
     
        				listp.add(map);
     
        				list=(ListView)findViewById(R.id.list);
     
        				adapter2 = new LazyAdapter(ListeProduits.this, listp);
     
        				list.setAdapter(adapter);
     
     
        				list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
     
        		            @Override
        		            public void onItemClick(AdapterView<?> parent, View view,
        		                                    int position, long id) {
     
        		            ...................
     
        		            }
        		        });
     
     
        				}
        		} catch (JSONException e) {
        			e.printStackTrace();
        		}	 
        	 }
        }
    LazyAdapter :

    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
    package com.example.test;
     
    public class LazyAdapter extends BaseAdapter {
     
        private Activity activity;
        private List<? extends Map<String, String>> data;
        private static LayoutInflater inflater=null;
        public ImageLoader imageLoader; 
     
        public LazyAdapter(Activity a,
    			List<? extends Map<String, String>> data) {
        	this.activity = a;
            this.data=data;
            inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader = new ImageLoader(activity.getApplicationContext());
     
            Log.i("Data",data.toString());
        }
     
        @Override
    	public int getCount() {
    		// TODO Auto-generated method stub
    		return data.size();
    	}
     
    	@Override
    	public Object getItem(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
     
    	@Override
    	public long getItemId(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
     
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            View vi=convertView;
     
            if(convertView==null) {
     
            vi = inflater.inflate(R.layout.list_v, null);
     
            TextView Produit=(TextView)vi.findViewById(R.id.Ligne1v2);;
            ImageView ImageProduit=(ImageView)vi.findViewById(R.id.ListeProduitImage);
            TextView Prix = (TextView)vi.findViewById(R.id.Ligne2v2);
            TextView Quantite = (TextView)vi.findViewById(R.id.Ligne4);
     
            Produit.setText(data.get(position).get("Produit"));
            Prix.setText(data.get(position).get("Prix"));
            Quantite.setText(data.get(position).get("Quantite"));
            imageLoader.DisplayImage(data.get(position).get("URLimage"), ImageProduit);
     
        }
    		return vi;      
        }
     
    }
    J'ai l'impression qu'il n'accède pas au getView

    merci d'avance

  2. #2
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut Example d afficher des enregistrement de puis une db mysql passant par Json
    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
     
    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);
    				}
    			});
     
    		}
     
    	}
    }
    voila le lien pour plus de detail

    http://www.androidhive.info/2012/05/...ith-php-mysql/

  3. #3
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut Custom ListView with Image and Text
    pour l utilisation de LazyAdapter voila un good exemple

    http://www.androidhive.info/2012/02/...mage-and-text/

  4. #4
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Points : 22
    Points
    22
    Par défaut
    Ce n'est pas un problème de récupération de données, lorsque j'affiche les data dans mon constructeur je retrouve bien tout.

    J'ai modifié un peu le code pour que cela ressemble à celui du tuto :

    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
    public class LazyAdapter extends BaseAdapter {
     
        private Activity activity;
        private ArrayList<HashMap<String, String>> data;
        private static LayoutInflater inflater=null;
        public ImageLoader imageLoader; 
     
        public LazyAdapter(Activity a,
    			ArrayList<HashMap<String, String>> d) {
        	activity = a;
            data=d;
            inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader = new ImageLoader(activity.getApplicationContext());
     
            Log.i("Data",data.toString());
        }
     
      	public int getCount() {
    		// TODO Auto-generated method stub
    		return data.size();
    	}
     
     
    	public Object getItem(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
     
     
    	public long getItemId(int position) {
    		// TODO Auto-generated method stub
    		return position;
    	}
     
     
        public View getView(final int position, View convertView, ViewGroup parent) {
            View vi=convertView;
     
            if(convertView==null) 
     
            vi = inflater.inflate(R.layout.list_v, null);
     
            TextView Produit=(TextView)vi.findViewById(R.id.Ligne1v2);;
            ImageView ImageProduit=(ImageView)vi.findViewById(R.id.ListeProduitImage);
            TextView Prix = (TextView)vi.findViewById(R.id.Ligne2v2);
            TextView Quantite = (TextView)vi.findViewById(R.id.Ligne4);
     
            HashMap<String, String> liste = new HashMap<String, String>();
            liste = data.get(position);
     
            // Setting all values in listview
            Produit.setText(liste.get(ListeProduits.TAG_PRODUIT));
            Prix.setText(liste.get(ListeProduits.TAG_PRIX));
            Quantite.setText(liste.get(ListeProduits.TAG_ENSTOCK));
            imageLoader.DisplayImage(liste.get(ListeProduits.TAG_URLIMAGE), ImageProduit);
     
            return vi;
        }
     
        }
    Mais il n'y toujours rien qui s'affiche.

    Avant j'utilisé cet adapter et ça "fonctionné"(des bugs et je n'utilisais pas la mémoire correctement) :

    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
    public class ListeProduitAdapter extends SimpleAdapter {
     
    	private List<? extends Map<String, String>> data;
    	private Context context;
     
    	public ListeProduitAdapter(Context context,
    			List<? extends Map<String, String>> data, int resource, String[] from,
    			int[] to) {
    		super(context, data, resource, from, to);
    		// TODO Auto-generated constructor stub	
    		this.context = context;
    		this.data = data;
     
    		Log.i("Data",data.toString());
    	}
    	@Override
    	    public View getView(final int position, View convertView, ViewGroup parent)
    	    {
    	        View MyView = convertView;
     
    	        if ( convertView == null )
    	        {
    	            LayoutInflater inflater = LayoutInflater.from(this.context);
    	            MyView = inflater.inflate(R.layout.list_v, null);
     
    	            TextView Produit = (TextView)MyView.findViewById(R.id.Ligne1v2);
    	            TextView Prix = (TextView)MyView.findViewById(R.id.Ligne2v2);
    	            TextView Quantite = (TextView)MyView.findViewById(R.id.Ligne4);
     
    				// TODO : On initialise les textviews en récupérant les valeurs dans data
     
    	            Produit.setText(data.get(position).get("Produit"));
    	            Prix.setText(data.get(position).get("Prix"));
    	            Quantite.setText(data.get(position).get("Quantite"));
     
    	            if(data.get(position).get("Quantite") == "En Stock") {
    	            		Quantite.setTextColor(Color.parseColor("#006600"));
    	            	} else {
    	            		Quantite.setTextColor(Color.parseColor("#FF0000"));
    	            	}
     
     
    	            new DownloadImageTask((ImageView) MyView.findViewById(R.id.ListeProduitImage))
    	            .execute(data.get(position).get("URLimage"));
     
    	        }
    	      return MyView;
    	    }
     
    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    	    ImageView bmImage;
     
    	    public DownloadImageTask(ImageView bmImage) {
    	        this.bmImage = bmImage;
    	    }
     
    	    protected Bitmap doInBackground(String... urls) {
    	        String urldisplay = urls[0];
    	        Bitmap mIcon11 = null;
    	        try {
    	            java.io.InputStream in = new java.net.URL(urldisplay).openStream();
    	            mIcon11 = BitmapFactory.decodeStream(in);
    	        } catch (Exception e) {
    	            //Log.e("Error", e.getMessage());
    	            //e.printStackTrace();
    	        }
    	        return mIcon11;
    	    }
     
    	    protected void onPostExecute(Bitmap result) {
    	        bmImage.setImageBitmap(result);
    	    }
    	}
    }

  5. #5
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut voila le mien et ca marche bien
    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
    public class LazyAdapter extends BaseAdapter {
     
        private Activity activity;
        private ArrayList<HashMap<String, String>> data;
        private static LayoutInflater inflater=null;
        public ImageLoader imageLoader; 
     
        public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
            activity = a;
            data=d;
            inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            imageLoader=new ImageLoader(activity.getApplicationContext());
        }
     
        public int getCount() {
            return data.size();
        }
     
        public Object getItem(int position) {
            return position;
        }
     
        public long getItemId(int position) {
            return position;
        }
     
        public View getView(int position, View convertView, ViewGroup parent) {
            View vi=convertView;
            if(convertView==null)
                vi = inflater.inflate(R.layout.actu_listitem, null);
     
            TextView titre_actu = (TextView)vi.findViewById(R.id.tx_title_actu); // title
            TextView text_actu = (TextView)vi.findViewById(R.id.tx_text_actu); // artist name
            TextView date_actu = (TextView)vi.findViewById(R.id.tx_date_actu); // duration
            ImageView imag_actu =(ImageView)vi.findViewById(R.id.img_actu); // thumb image
     
            HashMap<String, String> sActu = new HashMap<String, String>();
            sActu = data.get(position);
     
            // Setting all values in listview
            titre_actu.setText(sActu.get(AllactuActivity.TAG_TITRE_ACTU));
            text_actu.setText(sActu.get(AllactuActivity.TAG_TEXT_ACTU));
            date_actu.setText(sActu.get(AllactuActivity.TAG_DATE_ACTU));
     
            imageLoader.DisplayImage(sActu.get(AllactuActivity.TAG_IMAG_LINK), imag_actu);
            return vi;
        }
    }

  6. #6
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut verification layouts
    tu dois bien verifier les layouts aussi surtout les ids des object

  7. #7
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Points : 22
    Points
    22
    Par défaut
    C'est bon ça fonctionne !

    Bon maintenant comme l'informatique c'est géniale, j'ai un autre problème =)

    J'ai un editext pour rechercher dans la liste mais il aime pas :

    java.lang.ClassCastException : com.example.test.LazyAdapter cannot be cast to android.widget.Filterable

    Si quelqu'un a une solution je suis preneur mais je vais chercher de mon côté !

    Merci andronull !

  8. #8
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78
    Par défaut SearcchView
    je t en prie

    essaye ca pour le SearchView

    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
    import java.util.ArrayList;
     
    import android.app.Activity;
    import android.app.SearchManager;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.Menu;
    import android.widget.ExpandableListView;
    import android.widget.SearchView;
     
     
     
    public class MainActivity extends Activity implements 
    SearchView.OnQueryTextListener, SearchView.OnCloseListener { 
     
     
     
     
    private SearchView search; 
    private MyListAdapter listAdapter; 
    private ExpandableListView myList; 
    private ArrayList<Continent> continentList = new ArrayList<Continent>(); 
     
     
    @Override
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
    search = (SearchView) findViewById(R.id.search); 
    search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 
    search.setIconifiedByDefault(false); 
    search.setOnQueryTextListener(this); 
    search.setOnCloseListener(this); 
    //display the list 
    displayList(); 
    //expand all Groups 
    expandAll(); 
    } 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
    } 
    //method to expand all groups 
    private void expandAll() { 
    int count = listAdapter.getGroupCount(); 
    for (int i = 0; i < count; i++){ 
    myList.expandGroup(i); 
    } 
    } 
    //method to expand all groups 
    private void displayList() { 
    //display the list 
    loadSomeData(); 
    //get reference to the ExpandableListView 
    myList = (ExpandableListView) findViewById(R.id.expandableList); 
    //create the adapter by passing your ArrayList data 
    listAdapter = new MyListAdapter(MainActivity.this, continentList); 
    //attach the adapter to the list 
    myList.setAdapter(listAdapter); 
     
    //myList.setOnChildClickListener(myListItemClicked); 
    } 
    private void loadSomeData() { 
    ArrayList<Country> countryList = new ArrayList<Country>(); 
    Country country = new Country("1","heter",1,"im1"); 
    countryList.add(country); 
    country = new Country("2","bor",2,"im2"); 
    countryList.add(country); 
    country = new Country("3","snakker",3,"im3"); 
    countryList.add(country); 
    Continent continent = new Continent("Side 1",countryList); 
    continentList.add(continent); 
    countryList = new ArrayList<Country>(); 
    country = new Country("4","skriver",4,"im4"); 
    countryList.add(country); 
    country = new Country("5","leser",5,"im5"); 
    countryList.add(country); 
    country = new Country("6","regner",6,"im6"); 
    countryList.add(country); 
    continent = new Continent("Side 2",countryList); 
    continentList.add(continent); 
    } 
    @Override
    public boolean onClose() { 
    listAdapter.filterData(""); 
    expandAll(); 
    return false; 
    } 
    @Override
    public boolean onQueryTextChange(String query) { 
    listAdapter.filterData(query); 
    expandAll(); 
    return false; 
    } 
    @Override
    public boolean onQueryTextSubmit(String query) { 
    listAdapter.filterData(query); 
    expandAll(); 
    return false; 
    }
     
     
     
     
     
    }

  9. #9
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Points : 22
    Points
    22
    Par défaut
    Ah oui je vois ce que tu veux dire mais moi j'utilise un edittext dans le 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
    inputsearch = (EditText) findViewById(R.id.inputsearch);
     
     
            /**
             * Enabling Search Filter
             * */
            inputsearch.addTextChangedListener(new TextWatcher() {
     
                @Override
                public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
                    // When user changed the Text
                    ((Filterable) ListeProduits.this.adapter).getFilter().filter(cs);  
                }
     
                @Override
                public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                        int arg3) {
                    // TODO Auto-generated method stub
     
                }
                @Override
                public void afterTextChanged(Editable arg0) {
                    // TODO Auto-generated method stub                         
                }
            });
    Mais j'ai l'erreur que j'ai mise plus haut

  10. #10
    Membre régulier
    Homme Profil pro
    Architecte de base de données
    Inscrit en
    Février 2013
    Messages
    53
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Norvège

    Informations professionnelles :
    Activité : Architecte de base de données
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2013
    Messages : 53
    Points : 78
    Points
    78

  11. #11
    Membre à l'essai
    Homme Profil pro
    Inscrit en
    Décembre 2013
    Messages
    26
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Décembre 2013
    Messages : 26
    Points : 22
    Points
    22
    Par défaut
    Je mets en résolu la discussion, c'est un autre problème ça ^^

    PS : J'ai posté un autre problème par rapport à un viewpager et des fragments, si tu connais n'hésite pas =p !

    Merci !

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

Discussions similaires

  1. Problème Affichage Listview
    Par hjyf84 dans le forum VB.NET
    Réponses: 2
    Dernier message: 02/12/2013, 11h29
  2. [Débutant] WPF problème affichage listview
    Par yuco1334 dans le forum Windows Presentation Foundation
    Réponses: 7
    Dernier message: 01/12/2012, 20h58
  3. Problème affichage ListView
    Par frAydjwe dans le forum Composants graphiques
    Réponses: 5
    Dernier message: 19/05/2011, 16h01
  4. problème affichage par colonne (listview)
    Par skysee dans le forum C#
    Réponses: 2
    Dernier message: 19/09/2007, 12h32
  5. Problème affichage ListView
    Par sorcer1 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 24/01/2007, 14h52

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