我如何返回一个Runnable在这种方法吗? [英] How do I Return a Runnable in this Method?
问题描述
我不知道如何使一个Runnable方法的返回(或W /这个特殊的方法)。也许是我的想法错了(?)。任何帮助吗?日Thnx!
*这是继续执行/从<一个相关href=\"http://stackoverflow.com/questions/5889385/how-to-reuse-getexternalstoragestate/5889516#5889516\">this帖子。但认为它可能是对自己的问答。
在活动的onCreate:
的Runnable doIfMounted = orderASC_Label();
StorageStateChecker.performExternalStorageOperation(doIfMounted);
可运行的:
/ **
* - 默认列表顺序(升序)
* ================================================= ====================
* @返回
** /
公众可运行orderASC_Label(){
光标databaseCursor = db.rawQuery(
SELECT * FROM AC_list ORDER BY`label` ASC,NULL); Adapter_AC databaseListAdapter =新Adapter_AC(这一点,
R.layout.list_item,databaseCursor,新的String [] {标签
标题,说明,gotoURL},新的INT [] {
R.id.label,R.id.listTitle,R.id.caption,R.id.dummy}); databaseListAdapter.notifyDataSetChanged();
this.setListAdapter(databaseListAdapter);
返回/ *空; &LT; - 我该怎么做这里,使这个可运行* /
}
该StorageStateChecker类:
公共类StorageStateChecker {公共静态布尔performExternalStorageOperation(Runnable接口doIfMounted){
如果(android.os.Environment.getExternalStorageState()。等于(
android.os.Environment.MEDIA_MOUNTED)){ 如果(doIfMounted!= NULL){
doIfMounted.run();
}
返回true; }否则如果(android.os.Environment.getExternalStorageState()。等于(
android.os.Environment.MEDIA_UNMOUNTED)){
//Alerts.sdCardMissing(this);
}
返回false;
}
}
有没有理由使用方法返回一个Runnable。简单地声明一个成员(或静态最终)Runnable接口。所有code,它执行的推移在的run()
方法。
私有静态最后的Runnable ORDER_ASC =新的Runnable(){
公共无效的run(){
光标databaseCursor = db.rawQuery(
SELECT * FROM AC_list ORDER BY`label` ASC,NULL); Adapter_AC databaseListAdapter =新Adapter_AC(这一点,
R.layout.list_item,databaseCursor,新的String [] {标签
标题,说明,gotoURL},新的INT [] {
R.id.label,R.id.listTitle,R.id.caption,R.id.dummy}); databaseListAdapter.notifyDataSetChanged();
this.setListAdapter(databaseListAdapter);
}
};
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;
}
}
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.
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);
}
};
这篇关于我如何返回一个Runnable在这种方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!