Question

Je ne sais pas comment faire un retour sur une méthode exécutable (ou avec cette méthode particulière).J'ai peut-être une mauvaise idée de (?).De l'aide?thnx!

* Ceci est poursuivi / lié à ce message .Mais je pensais que ça pouvait être un Q en soi.

Dans les activités onCreate:

Runnable doIfMounted = orderASC_Label();
    StorageStateChecker.performExternalStorageOperation(doIfMounted );

Le Runnable:

/**
 * -- Default List Order (Ascending)
 * =====================================================================
 * @return 
 **/
public Runnable orderASC_Label() {
    Cursor databaseCursor = db.rawQuery(
            "SELECT * FROM AC_list ORDER BY `label` ASC", null);

    Adapter_AC databaseListAdapter = new Adapter_AC(this,
            R.layout.list_item, databaseCursor, new String[] { "label",
                    "title", "description", "gotoURL" }, new int[] {
                    R.id.label, R.id.listTitle, R.id.caption, R.id.dummy });

    databaseListAdapter.notifyDataSetChanged();
    this.setListAdapter(databaseListAdapter);
    return /*null; <-- What do I do here to make this runnable */
}

La classe StorageStateChecker:

public class StorageStateChecker {

public static boolean performExternalStorageOperation(Runnable doIfMounted) {
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED)) {

        if (doIfMounted != null) {
            doIfMounted.run();
        }
        return true;

    } else if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_UNMOUNTED)) {
         //Alerts.sdCardMissing(this);
    }
    return false;
}
}
Était-ce utile?

La solution

Il n'y a aucune raison d'utiliser une méthode pour renvoyer un Runnable.Déclarez simplement un membre (ou statique final) exécutable.Tout le code qui s'exécute va dans la méthode run().

private static final Runnable ORDER_ASC = new Runnable() {
    public void run() {
        Cursor databaseCursor = db.rawQuery(
            "SELECT * FROM AC_list ORDER BY `label` ASC", null);

        Adapter_AC databaseListAdapter = new Adapter_AC(this,
            R.layout.list_item, databaseCursor, new String[] { "label",
                    "title", "description", "gotoURL" }, new int[] {
                    R.id.label, R.id.listTitle, R.id.caption, R.id.dummy });

        databaseListAdapter.notifyDataSetChanged();
        this.setListAdapter(databaseListAdapter);
    }
};
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top