2014-02-14 52 views
0

這裏有什麼,我試圖做是否可以在java中調用回外部嵌套類?

public class BookModel { 

     private void update_method() { 
      get_info task = new get_info(this) 
      task.exicute(some args); 
     } 

     public void finishedCallback(some_return_type result) { 
     // do some stuff when finsiehd. 
     } 


    class get_info extends AsyncTask<HashMap<String, String>, Void, dataType> 
    { 
     private BookModel bookModel; 

     public get_info (BookModel reset) { 
      bookModel = reset; 
     } 

     @Override 
     protected dataType doInBackground(arg...) 
         some procscessing. 
     } 

     protected void onPostExecute(dataType result) { 
      bookModel.finishedCallback(result); 
     } 
    } 
    } 

我怎樣才能得到這個回調系統的工作......我試着使用inteface還有一個例子,但沒有奏效。我認爲這是因爲你需要3個帶接口的類(如果我錯了,請糾正我)。我也歡迎任何建議,但理想情況下,如果可能,我希望將此功能保留在同一個類中。任何幫助,這將不勝感激。

+0

'你需要3類接口'你從哪裏得到的? – njzk2

+0

你的doInBackground的聲明是錯誤的。你需要受保護的getProductInfoBriefFull doInBackground(Void ...){' – njzk2

+0

@ njzk2好吧,我有點計算接口作爲一個類...所以你需要接口,類發出的信號和類接收信號......但如果你不把接口作爲一個類來計算,那麼你只需要兩個...但問題似乎是這個類是嵌套的。 –

回答

1

試試這個。

這是爲我工作。

public class BookModel implements get_info.xyz { 

    private void update_method() { 
     get_info task = new get_info(this); 
     task.exicute(some args); 
    } 

    public void finishedCallback(String result) { 
    // do some stuff when finsiehd. 
    } 

} 
//---------------------------------- 
class get_info extends AsyncTask<HashMap<String, String>, Void, dataType> 
{ 


    private xyz bookModel; 
    public interface xyz 
    { 
     void finishedCallback(String str); 
    } 
    public get_info (xyz reset) { 
     bookModel = reset; 
    } 

    @Override 
    protected dataType doInBackground(arg...) 
        some procscessing. 
    } 

    protected void onPostExecute(dataType result) { 
     bookModel.finishedCallback(result); 
    } 
}