2011-05-05 2 views
0

나는 Runnable Method (또는이 특별한 방법으로)에서 Return을 만드는 법을 모른다. 나는 (?)에 잘못된 생각을 가지고 있을지도 모른다. 어떤 도움이 필요합니까? 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