2012-02-29 113 views
-1

由於java不支持多重繼承,所以在解決此問題時遇到了問題。無法擴展ListActivity和AsyncTask

這就是我想做的事:

public class CallForwardActivity extends ListActivity /* This is there I want to extend AsyncTask */ implements OnSharedPreferenceChangeListener 
{ 

... // creating and initializing stuff 

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 

    userInfo = this.getSharedPreferences(USERINFO_FILE, 0); 
    userInfo.registerOnSharedPreferenceChangeListener(this); 
    userControl = new UserController(context); 
    ListView lv = getListView(); 
    lv.setTextFilterEnabled(true); 
    //setListAdapter(new ArrayAdapter<String>(this, R.layout.callforward_items, R.id.callforward_item_text, callforwardLabels)); 

    list = new ArrayList<HashMap<String,String>>(); 

    callForwardList = new SimpleAdapter( 
      this, 
      list, 
      R.layout.callforward_items, 
      new String[] { "line1","line2" }, 
      new int[] { R.id.callforward_item_text, R.id.callforward_number }); 



    populateList(); 
    setListAdapter(callForwardList); 

    lv.setOnItemClickListener(new OnItemClickListener() { 

    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    { 
     CustomDialog(); // this will make the asynchronous task call if the user presses "OK" within the dialog box. 
    } 

    }); 

} 

如何去進行調用異步不延長的AsyncTask?

回答

4

只需創建另一個類,延伸AsyncTask並在ListActivity中使用它。如果你喜歡,你可以讓它內在。希望這可以幫助。

1

errrmmm ....你不能在java中擴展兩個類,你可以實現很多接口,但擴展一個類。你應該創建另一個內部類,它擴展了AsyncTask < ..,..>,並在那裏做你的後臺作業。

更多關於多重繼承在Java中 http://java.sys-con.com/node/37748

0

什麼是你要使用延伸的AsyncTask活動中使用的情況下,的AsyncTask用於後臺進程,胡亞蓉組件用於提供UI

你是嘗試UIThread擴展BackgroundThread,這意味着你正在建立像'UIThread is-a BackgroundThread'的關係。

我覺得還有另一種方法來解決你的用例。