显示进度对话框 OnItemClick
我有一个 ListView,其中包含使用 JSON 检索的项目列表,并且我想在项目单击时显示 ProgressDialog。
listNews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
ProgressDialog dialog;
dialog = ProgressDialog.show(v.getContext(), "Please wait..", "Loading data", true);
dialog.setCancelable(false);
dialog.show();
News n = (News)listNews.getItemAtPosition(position);
Intent myIntent = new Intent(v.getContext(), SingleActivity.class);
myIntent.putExtra("actu_id", n.ID);
dialog.dismiss();
startActivityForResult(myIntent, 0);
}
});
进度对话框未显示... 当我在 SingleActivity.class 的 OnCreate 中定义此 ProgressDialog 时遇到同样的问题
你能帮我吗?
对不起我的英语...
I've a ListView with a list of item retrieving with JSON and i want to show a ProgressDialog on item click.
listNews.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View v, int position,
long arg3) {
ProgressDialog dialog;
dialog = ProgressDialog.show(v.getContext(), "Please wait..", "Loading data", true);
dialog.setCancelable(false);
dialog.show();
News n = (News)listNews.getItemAtPosition(position);
Intent myIntent = new Intent(v.getContext(), SingleActivity.class);
myIntent.putExtra("actu_id", n.ID);
dialog.dismiss();
startActivityForResult(myIntent, 0);
}
});
ProgressDialog not showing...
Same problem when I define this progressDialog in OnCreate in SingleActivity.class
Can you help me ?
Sorry for my english ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这是因为你立即驳回了它
I think it is because you are dismissing it right away
这是与您的工作流程相关的问题。由于您正在 UI 线程上执行其他任务,因此不会显示 ProgressDialog。
您应该生成一个线程来完成额外的工作,然后关闭对话框并使用 runOnUiThread() 或处理程序启动新的 Intent。
不过,最好的选择是使用 AsyncTask,在 PreExecute() 上显示 ProgressDialog,在 doInBackground() 中完成工作,然后在 PostExecute() 上关闭它并启动新活动。
It's a problem related with your workflow. Since you're doing additional tasks on the UI thread, the ProgressDialog doesn't get to be shown.
You should either spawn a thread for doing the extra work, then dismiss your dialog and launch your new Intent with runOnUiThread() or with a Handler.
Although, the best option would be using AsyncTask, showing your ProgressDialog onPreExecute(), doing your work in doInBackground() and then dismissing it onPostExecute() and launching your new activity.