如何在此方法中返回Runnable?

时间:2011-05-05 18:33:31

标签: android listview return sd-card runnable

我不知道如何在Runnable方法上进行返回(或者使用这种特定方法)。我可能有想法(?)。有帮助吗?日Thnx!

*这是this post继续/相关的。但是认为它本身可能是一个Q.

在关于创造的活动中:

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

The 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 */
}

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;
}
}

1 个答案:

答案 0 :(得分:1)

没有理由使用方法返回Runnable。只需声明一个成员(或静态最终)Runnable。执行的所有代码都在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);
    }
};