2011-05-05 87 views
0

我不知道如何在Runnable方法(或w /這個特定的方法)上進行返回。我可能對(?)有錯誤的想法。任何幫助?日Thnx!如何在此方法中返回Runnable?

*這是從this post繼續/相關。但認爲這可能是一個問題。

在活動的onCreate:

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

了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

沒有理由使用方法返回一個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); 
    } 
}; 
+0

我明白了。日Thnx!我會試一試。 – CelticParser 2011-05-05 18:41:41