如何在此方法中返回可运行对象?
我不知道如何返回可运行方法(或使用此特定方法)。我的想法可能是错误的(?)。有什么帮助吗?谢谢!
*这是这篇文章的继续/相关内容。但我认为它本身就可以成为一个问题。
在 Activity 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;
}
}
I don't know how to make a Return on a Runnable Method (or w/this particular method). I may have the idea wrong to(?). Any help? thnx!
*This is continued/related from this post. But thought it could be a Q on its own.
In the Activities onCreate:
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 */
}
The StorageStateChecker class:
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;
}
}
没有理由使用方法来返回 Runnable。只需声明一个成员(或静态最终)Runnable。所有执行的代码都在
run()
方法中。There's no reason to use a method to return a Runnable. Simply declare a member (or static final) Runnable. All the code that executes goes in the
run()
method.