无法扩展ListActivity和AsyncTask

问题描述:

由于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?

只需创建另一个类,延伸AsyncTask并在ListActivity中使用它。如果你喜欢,你可以让它内在。希望这可以帮助。

errrmmm ....你不能在java中扩展两个类,你可以实现很多接口,但扩展一个类。你应该创建另一个内部类,它扩展了AsyncTask < ..,..>,并在那里做你的后台作业。

更多关于多重继承在Java中 http://java.sys-con.com/node/37748

什么是你要使用延伸的AsyncTask活动中使用的情况下,的AsyncTask用于后台进程,胡亚蓉组件用于提供UI

你是尝试UIThread扩展BackgroundThread,这意味着你正在建立像'UIThread is-a BackgroundThread'的关系。

我觉得还有另一种方法来解决你的用例。