Java AsyncTask调用ProgressDialog.dimiss方法时出错
我使用Java AsyncTask调用ProgressDialog.dimiss方法时出错,java,android,listview,android-intent,android-asynctask,Java,Android,Listview,Android Intent,Android Asynctask,我使用AsyncTask从服务器获取数据,为我的listview构建适配器。但是如果我在异步任务中使用ProgressDialog,我会得到一个错误 代码: 文件AsyncTaskSetAdapterListViewDetail.java public class AsyncTaskSetAdapterListViewDetail extends AsyncTask<Void, Void, List<Map<String, Object>>> {
AsyncTask
从服务器获取数据,为我的listview
构建适配器。但是如果我在异步任务
中使用ProgressDialog
,我会得到一个错误
代码:
文件AsyncTaskSetAdapterListViewDetail.java
public class AsyncTaskSetAdapterListViewDetail extends AsyncTask<Void, Void, List<Map<String, Object>>> {
private final String query;
private final Context ctx;
private final ProgressDialog Loading;
public final HashMap<String, Object> Data;
private final View listv;
public AsyncTaskSetAdapterListViewDetail(final String query, final Context ctx, View listv, HashMap<String, Object> Data) {
this.query = query;
this.ctx = ctx;
this.Loading = new ProgressDialog(ctx);
this.listv = listv;
this.Data = Data;
}
@Override
protected void onPreExecute(){
super.onPreExecute();
Loading.setMessage("Loading...");
Loading.setCancelable(false);
Loading.show();
}
@Override
protected List<Map<String, Object>> doInBackground(final Void... voids) {
List<Map<String, Object>> BrightCoveData = new ArrayList<Map<String, Object>>();
BrightCoveClient bcClient = new BrightCoveClient();
String QueryType = (String) Data.get("QueryType");
if(QueryType == "bccategory")
{
BrightCoveData = bcClient.QueryData(query, ctx);
}
else if(QueryType == "bcplaylist")
{
BrightCoveData = bcClient.QueryDataPlaylist(query, ctx);
}
return BrightCoveData;
}
@Override
protected void onPostExecute(List<Map<String, Object>> result) {
super.onPostExecute(result);
String[] fromStr = (String[]) Data.get("StringFrom");
int[] toInt = (int[]) Data.get("ToInt");
String strClass = listv.getClass().toString();
String[] typeView = strClass.split("\\.");
int resource = (Integer) Data.get("Resource");
String type = typeView[typeView.length - 1];
for (Map<String, Object> map : result) {
String videoID = map.get("videoID").toString();
String name = map.get("title").toString();
String description = map.get("description").toString();
String duration = map.get("duration").toString();
if (!VideoFunctions.isVideoExisted(videoID)) {
VideoFunctions.addVideo(videoID, name, "", description, duration, "");
}
}
ListAdapter adapter = new OoyalaVideoListAdapter(ctx, result, resource, fromStr,toInt);
if ( type.equalsIgnoreCase("ListView")) {
((ListView) listv).setAdapter(adapter);
}
else {
((AbsSpinner) listv).setAdapter((SpinnerAdapter) adapter);
}
if (Loading.isShowing()){
Loading.dismiss();
}
}
}
这个错误意味着什么?我以前在其他ListView中使用过AsyncTask,没有错误。也许是因为我更换了布局
文件detail_layout.xml
尝试在
onPostExecute
方法开始时关闭progressdialog
@Override
protected void onPostExecute(List<Map<String, Object>> result) {
super.onPostExecute(result);
if (Loading.isShowing()){
Loading.dismiss();
}
..........//your code
.................}
@覆盖
受保护的void onPostExecute(列表结果){
super.onPostExecute(结果);
if(加载.isShowing()){
Loading.dispose();
}
……您的代码
.................}
试试这个
public AsyncTaskSetAdapterListViewDetail(final String query, final Context ctx, View listv, HashMap<String, Object> Data) {
this.query = query;
this.ctx = ctx;
if(this.Loading!=null)
{
if (Loading.isShowing())
Loading.dismiss();
}
this.Loading = new ProgressDialog(ctx);
this.listv = listv;
this.Data = Data;
}
public AsyncTaskSetAdapterListViewDetail(最终字符串查询、最终上下文ctx、视图列表V、HashMap数据){
this.query=query;
this.ctx=ctx;
if(this.Loading!=null)
{
if(加载.isShowing())
Loading.dispose();
}
this.Loading=newprogressdialog(ctx);
this.listv=listv;
这个。数据=数据;
}
您是在旋转手机时遇到此错误,还是通常会出现此错误?我默认使用横向屏幕运行,而不是旋转手机。谢谢当您在活动中调用此类时,在该活动中还可以创建另一个进度对话框?@user2830969请参阅链接。它可能对你有帮助。谢谢,但它仍然不起作用。删除时出错,但postExecute方法中未完成ProgressDialog(dimiss)如果(加载!=null){Loading.disease();}
@user2830969是否尝试过上述修改?现在是否也无法关闭加载程序?你能把你现在拥有的代码重新发布吗?@GrlsHu。你好我需要你的帮助。胡·阿姆达瓦德J6U号。please@GrIsHu我正在使用面部改变应用程序。所以基本上我是在用手势。但至少我无法正确修复。功能正常。但当我将卡通类型的图像设置为主图片并触摸该图像视图时,它就会跳出屏幕。我想阻止它。。如何?你不能将你的问题与你的问题一起发布吗@Piyushgupta提供您的question@GrIsHu我已经删除了。因为没有帮助,所有人都被否决了。我的所有功能都正常工作。也使用多点触摸,但我不能得到正确的结果
@Override
protected void onPostExecute(List<Map<String, Object>> result) {
super.onPostExecute(result);
if (Loading.isShowing()){
Loading.dismiss();
}
..........//your code
.................}
public AsyncTaskSetAdapterListViewDetail(final String query, final Context ctx, View listv, HashMap<String, Object> Data) {
this.query = query;
this.ctx = ctx;
if(this.Loading!=null)
{
if (Loading.isShowing())
Loading.dismiss();
}
this.Loading = new ProgressDialog(ctx);
this.listv = listv;
this.Data = Data;
}