gpt4 book ai didi

android - 从 AsyncTask 更新 ListView

转载 作者:行者123 更新时间:2023-11-29 15:22:00 25 4
gpt4 key购买 nike

我有两个类,HomeActivity 和 CustomListAdapter。HomeActivity 类扩展了一个 Activity ,然后更新了一个 ListView 。我使用扩展了 BaseAsapter 的 CustomListAdapter 类将数据填充到 ListView 中。一切正常,但我想加载后台任务中的数据。当我这样做时,出现错误。这是我对 AyncTask 类的 onPostExecute 的实现。

@Override
protected void onPostExecute(HomeActivity Params){
progressDialog.dismiss();
runOnUiThread(new Runnable(){
public void run(){
final ListView lv1 = (ListView) findViewById(R.id.listings);
lv1.setAdapter(new CustomListAdapter(this, shares));
}
});

}

我收到一条错误消息,告诉我应该更改 CustomListAdapter 上的构造函数。但是当我更改它时,一切都变得糟糕起来。这个我也试过不成功

final ListView lv1 = (ListView) findViewById(R.id.listings);
lv1.setAdapter(new CustomListAdapter(this, shares));

shares 是来自网络服务的数据数组列表。这是 CustomListAdapter 类中的构造函数

 public CustomListAdapter(Context context, ArrayList listData) {
this.listData = listData;
layoutInflater = LayoutInflater.from(context);
}

如何解决?非常感谢您的帮助。

最佳答案

你必须改变:

 @Override
protected void onPostExecute(HomeActivity Params){
progressDialog.dismiss();
runOnUiThread(new Runnable(){
public void run(){
final ListView lv1 = (ListView) findViewById(R.id.listings);
lv1.setAdapter(new CustomListAdapter(YourActivity.this, shares));
}
});

}

关于android - 从 AsyncTask 更新 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17422705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com