Android 无法同时扩展ListActivity和AsyncTask

Android 无法同时扩展ListActivity和AsyncTask,android,android-asynctask,extends,Android,Android Asynctask,Extends,因为java不支持多重继承,所以我很难做到这一点 这就是我想做的: public class CallForwardActivity extends ListActivity /* This is there I want to extend AsyncTask */ implements OnSharedPreferenceChangeListener { ... // creating and initializing stuff @Override public void onCrea

因为java不支持多重继承,所以我很难做到这一点

这就是我想做的:

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.
    }

  });

}
public class CallForwardActivity extends ListActivity/*这就是我想要扩展AsyncTask*/实现的共享首选项ChangeListener
{
…//创建和初始化内容
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
userInfo=this.getSharedReferences(userInfo_文件,0);
userInfo.RegisterOnSharedReferenceChangeListener(此);
userControl=新的UserController(上下文);
ListView lv=getListView();
lv.setTextFilterEnabled(真);
//setListAdapter(新的ArrayAdapter(this,R.layout.callforward_items,R.id.callforward_item_text,callforwardLabels));
列表=新的ArrayList();
callForwardList=新的SimpleAdapter(
这
列表
R.layout.callforward\u项,
新字符串[]{“line1”,“line2”},
新int[]{R.id.callforward\u item\u text,R.id.callforward\u number});
大众主义者();
setListAdapter(callForwardList);
lv.setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、整型位置、长id)
{
CustomDialog();//如果用户在对话框中按“OK”,将进行异步任务调用。
}
});
}

如何在不扩展AsyncTask的情况下使调用异步?

只需创建另一个扩展AsyncTask的类,并在
列表活动中使用它。如果您愿意,可以将其设置为内部。希望这会有所帮助。

errrmmm…在java中无法扩展两个类您可以实现许多接口but扩展一个类。您应该创建另一个内部类来扩展AsyncTask,并在那里执行后台工作

更多关于java中多重继承的信息

您试图使用活动扩展asynctask的用例是什么,asynctask用于后台进程,activity组件用于提供UI

您正在尝试UIThread extends BackgroundThread,这意味着您正在建立一种类似于“UIThread is-a BackgroundThread”的关系

我觉得有另一种方法可以解决您的用例