Aller au contenu
View in the app

A better way to browse. Learn more.

Forum de Frandroid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ListView / ArrayList / ArrayAdapter / Comment bien faire

Featured Replies

Posté(e)

Mon Activity ne contient qu'une ListView (qui affiche des String).

J'ai donc choisi de prendre une ListActivity

J'ai une ArrayList (de String), donc le contenu change fréquemment (en dehors du thread UI).

J'ai donc pris un ArrayAdapter pour faire ça :

this.list = new ArrayList();
this.adapter = new ArrayAdapter(this, R.layout.simple_list_item_1, this.list);
this.setListAdapter(this.adapter);

2 solutions s'offrent à moi pour modifier les données dans ma ListView :

- "this.adapter.add("Time : " + System.currentTimeMillis());"

- changer dans mon ArrayList, puis notifier l'Adapter via "this.adapter.notifyDataSetChanged();"

Problème : toute intervention sur l'Adapter (changement direct, ou notification) nécessite d'être dans le Thread graphique.

Pour moi, ce n'est pas un problème, ça peut se résoudre par :

- Activity.runOnUIThread()

- View.post()

- Un Handler

Quelle est la meilleure méthode ?

Il n'existe pas une méthode plus simple ?

Merci !

Posté(e)

Déjà tu peux activer une option sur ArrayAdapter qui fait le notify tout seul dès que tu fait un add (setNotifyOnChange). Ensuite tu fais des post avec Handler ou des View.post() car ça change rien (y'a pas une méthode mieux que l'autre).

Rejoignez la conversation

Vous pouvez poster maintenant et vous enregistrez plus tard. Si vous avez un compte, connectez-vous maintenant pour poster.

Invité
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Répondre à ce sujet…

Account

Navigation

Rechercher

Rechercher

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.