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 :

Démarrer activité depuis un BaseAdapter


Sujet :

Android

  1. #1
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut Démarrer activité depuis un BaseAdapter
    Bonjour la communauté j utilise un baseadapter qui me permet d afficher une listeview avec onglet alphabetique .

    pour essayer de voir si tout est ok j ai mis une fonction toast qui marche bien par contre lorsque je remplace par un intent pour la lancer mon activity rien ne se passe et je n ai pas d erreurs.J ai regarde un peu de partout pas trouve pourquoi . je vous le script si quelqu un peu m indique ou est mon erreur merci par avance .
    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
    
    
    package com.lolea.first;
    
    import java.util.Vector;
    
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.LinearLayout;
    import android.widget.TextView;
    import android.widget.Toast;
    
    import com.lolea.index.table.to.Book;
    
    public class UserListAdapter extends BaseAdapter {
    
    	private static final String TAG = UserListAdapter.class.getName();
    	private Activity activity;
    	private Vector<Book> items;
    //	private Context mContext;
    
    	public UserListAdapter(Activity activity, Vector<Book> items) {
    		Log.i(TAG, TAG);
    		this.activity = activity;
    		this.items = items;
    	}
    
    	public View getView(final int position, View convertView, ViewGroup parent) {
    
    		ViewHolder holder;
    
    		if (convertView == null) {
    
    			LayoutInflater inflater = activity.getLayoutInflater();
    			convertView = inflater.inflate(R.layout.listrow_user, null);
    			holder = new ViewHolder();
    
    			holder.name = (TextView) convertView.findViewById(R.id.nameTV);
    			holder.headingLL = (LinearLayout) convertView
    					.findViewById(R.id.headingLL);
    			holder.headingTV = (TextView) convertView
    					.findViewById(R.id.headingTV);
    			holder.nameLL = (LinearLayout) convertView
    					.findViewById(R.id.nameLL);
    
    			convertView.setTag(holder);
    
    		} else {
    			holder = (ViewHolder) convertView.getTag();
    		}
    
    		if (position < items.size()) {
    
    			final Book book = items.get(position);
    			if (book != null && (book.getProduits().length() == 1)) {
    				holder.nameLL.setVisibility(View.GONE);
    				holder.headingLL.setVisibility(View.VISIBLE);
    				holder.headingTV.setText(book.getProduits());
    				holder.headingLL
    						.setBackgroundColor(android.R.color.transparent);
    			} else {
    				holder.nameLL.setVisibility(View.VISIBLE);
    				holder.headingLL.setVisibility(View.GONE);
    				holder.name.setText(book.getProduits());
    
    				View ll = (LinearLayout) holder.name.getParent();
    				ll.setFocusable(true);
    				ll.setSelected(true);
    				ll.setOnClickListener(new OnClickListener() {
    				
    					public void onClick(View v) {
    						/* action sur le clic */
    						
    						if (book.getListe() == "A") {
    							;
    							Intent menuIntent = new Intent(activity, MenuproduitsAB.class);
    				startActivity(menuIntent)  ici le code pour demarrer mon activity mais rien ne se passe
    							finish();
    							
    
    							
    						}
    
    						else if (book.getListe() == "B") {
    							Intent menuIntent = new Intent(activity
    									.getApplicationContext(),
    									MainActivity.class);
    							Toast.makeText(activity.getApplicationContext(),Ici  le toast qui fonctionne bien
    									"Vous avez cliquez sur produit liste B",
    									Toast.LENGTH_SHORT).show();
    
    							startActivity(menuIntent);
    							finish();
    
    						} else if (book.getListe() == "C") {
    							Intent menuIntent = new Intent(activity
    									.getApplicationContext(),
    									MainActivity.class);
    
    							startActivity(menuIntent);
    							finish();
    							Toast.makeText(activity.getApplicationContext(),
    									"Vous avez cliquez sur produit liste C",
    									Toast.LENGTH_SHORT).show();
    
    						}
    
    					}
    
    					private Context getBaseContext() {
    						// TODO Auto-generated method stub
    						return null;
    					}
    
    					private void startActivity(Intent menuIntent) {
    						// TODO Auto-generated method stub
    
    					}
    				});
    			}
    		}
    
    		return convertView;
    	}
    
    	protected Context getApplicationContext() {
    		// TODO Auto-generated method stub
    		return null;
    	}
    
    	protected void finish() {
    		// TODO Auto-generated method stub
    
    	}
    
    	private static class ViewHolder {
    		TextView name, headingTV;
    		LinearLayout nameLL, headingLL;
    	}
    
    	@Override
    	public int getCount() {
    		return items.size();
    	}
    
    	@Override
    	public Object getItem(int position) {
    		return items.get(position);
    	}
    
    	@Override
    	public long getItemId(int position) {
    		return position;
    	}
    }


    Cordialement Eric

  2. #2
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    book.getListe() == "A" ???

    La comparaison de chaines c'est .equals() pas '=='
    '==' c'est la comparaison d'objets (au sens "vrai")
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  3. #3
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    Merci pour cette précision concernant l égalité. j ai change cela est plus propre et conventionnel , par contre cela ne résout pas mon problème de mon activité qui ne démarre pas ..je cherche j ai modifie le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    	if (book.getListe().equals("A")  ) {
    							;
    							Intent menuIntent = new Intent(getApplicationContext(), MenuproduitsAB.class);
    							startActivity(menuIntent);
    							finish();
     
     
     
    						}
    toujours pas de demarrage de l activite quand je clic l application se ferme et message desole fermeture soudaine de l application forcer la fermeture


    je transmets le logcat

    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
     
     
    01-13 11:33:47.103: I/CustomListIndex(327): CustomListIndex
    01-13 11:33:47.264: I/com.lolea.first.UserListAdapter(327): com.lolea.first.UserListAdapter
    01-13 11:33:47.313: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.333: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.423: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.433: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.464: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.473: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.493: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.503: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.523: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.543: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.563: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.573: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.582: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.603: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.622: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.642: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.673: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.682: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.703: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.712: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.733: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.743: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.763: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.772: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.883: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:47.893: W/Resources(327): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f06000f}
    01-13 11:33:53.053: D/AndroidRuntime(327): Shutting down VM
    01-13 11:33:53.053: W/dalvikvm(327): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    01-13 11:33:53.092: E/AndroidRuntime(327): FATAL EXCEPTION: main
    01-13 11:33:53.092: E/AndroidRuntime(327): java.lang.NullPointerException
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.content.ComponentName.<init>(ComponentName.java:75)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.content.Intent.<init>(Intent.java:2678)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at com.lolea.first.UserListAdapter$1.onClick(UserListAdapter.java:83)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.view.View.performClick(View.java:2408)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.view.View$PerformClick.run(View.java:8816)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.os.Handler.handleCallback(Handler.java:587)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.os.Handler.dispatchMessage(Handler.java:92)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.os.Looper.loop(Looper.java:123)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at android.app.ActivityThread.main(ActivityThread.java:4627)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at java.lang.reflect.Method.invokeNative(Native Method)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at java.lang.reflect.Method.invoke(Method.java:521)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    01-13 11:33:53.092: E/AndroidRuntime(327): 	at dalvik.system.NativeStart.main(Native Method)
    je vois pas pourquoi ca fonctionne pas merci de vos réponses

  4. #4
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Pourquoi utiliser getApplicationContext() ?
    (alors qu'on a "this") ?
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  5. #5
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    je ne peux utiliser le this car il me claque une erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
     
    The constructor Intent(new View.OnClickListener(){}, Class<MenuproduitsAB>) is undefined

  6. #6
    Membre du Club
    Homme Profil pro
    Administrateur Télécoms
    Inscrit en
    Décembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Administrateur Télécoms
    Secteur : Service public

    Informations forums :
    Inscription : Décembre 2010
    Messages : 67
    Points : 52
    Points
    52
    Par défaut
    bonsoir je viens de résoudre mon probleme pour lance mon activité il suffisait de renseigner l activité avec le getapplication context voila le bout de code je cloture le post merci encore nicroman de ton aide

    voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    
    	if (book.getListe().equals("A")  ) {
    							
    							Intent menuIntent = new Intent(activity,MenuproduitsAB.class);activity et le context
    							activity.startActivity(menuIntent);et la activity qui lance montre activité
    							finish();

    }

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

Discussions similaires

  1. Démarrer une activité depuis une AsyncTask
    Par DummyDev dans le forum Android
    Réponses: 6
    Dernier message: 10/01/2013, 18h10
  2. Actualisation d'une activité depuis une autre
    Par eento dans le forum Android
    Réponses: 2
    Dernier message: 08/08/2012, 01h51
  3. Agir sur une activité depuis une View personalisée
    Par grunk dans le forum Composants graphiques
    Réponses: 14
    Dernier message: 09/08/2011, 10h25
  4. Réponses: 2
    Dernier message: 07/07/2011, 13h59
  5. [PHP 5.2] Démarrer Apache2 depuis php
    Par max-mag dans le forum Langage
    Réponses: 2
    Dernier message: 01/10/2010, 11h48

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