2011-05-05 220 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