ProgressDialog的Android的AsyncTask [英] ProgressDialog Android AsyncTAsk
本文介绍了ProgressDialog的Android的AsyncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要显示一个ProgressDialog时pressing我的列表视图中的任何项目,而详细类是在后台转,我知道我必须使用AsyncTask的,但我不能弄清楚如何,任何一个可以帮助我好吗?
这是我的片段,我哪里来显示ProgressDialog
公共类FeedPlayerIndexFragment扩展SherlockFragment {
字符串URL =http://www.toto.com/index.php?format=feed&type=rss;
ArrayList的<物品>饲料;
AndroidSaxFeedParser feedParser =新AndroidSaxFeedParser(URL);
@覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,
捆绑savedInstanceState){
// TODO自动生成方法存根
馈送= feedParser.parse();
查看查看= inflater.inflate(R.layout.main,集装箱,FALSE);
CustomItemAdapter_News LFA =新CustomItemAdapter_News(getActivity()getApplicationContext(),饲料);
((ListView控件)view.findViewById(R.id.listFeed))setAdapter(LFA)。 ((ListView控件)view.findViewById(R.id.listFeed))setOnItemClickListener。(新OnItemClickListener(){
公共无效onItemClick(适配器视图<>为arg0,视图V,INT位置,长的id){
束B =新包();
b.putInt(位置,位置);
b.putString(URL,URL);
意向意图=新意图(getActivity()getApplicationContext(),DetailActivity.class。);
intent.putExtras(二);
startActivity(意向);
}
});
返回视图。
}
}
这是我的详细活动哗哗应该打开后台
公共类DetailActivity延伸活动{
字符串descriptionFinale = NULL,imageFinale = NULL,网址;
INT位置;
TextView的description_,滴度,日期;
ImageView的image_;
ArrayList的<物品>饲料;的WebView contentWebView;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.detail);
束B = getIntent()getExtras()。
位置= b.getInt(位置);
URL = b.getString(URL);
AndroidSaxFeedParser feedParser =新AndroidSaxFeedParser(URL);
馈送= feedParser.parse();
日期=(的TextView)findViewById(R.id.date);
contentWebView =(的WebView)findViewById(R.id.contentWebView);
效价=(的TextView)findViewById(R.id.titre); date.setText(feeds.get(位置).getTitle());
GetDescriptionWebView.getDescriptionImage(位置,饲料,contentWebView);
titre.setText(Postulé乐:+ GetDateFormat.getDate(位置,饲料));}}
解决方案
您可以试试这个code
公共类DetailActivity扩展活动
{
字符串descriptionFinale = NULL,imageFinale = NULL,网址;
INT位置;
TextView的description_,滴度,日期;
ImageView的image_;
ArrayList的<物品>饲料;的WebView contentWebView;
ProgressDialog对话框;@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.detail); 提要=新的ArrayList<物品取代;
contentWebView =(的WebView)findViewById(R.id.contentWebView);
日期=(的TextView)findViewById(R.id.date);
效价=(的TextView)findViewById(R.id.titre);
束B = getIntent()getExtras()。
位置= b.getInt(位置);
URL = b.getString(URL);
AndroidSaxFeedParser feedParser =新AndroidSaxFeedParser(URL);
新MyFetchTask()执行();}公共类MyFetchTask扩展的AsyncTask<对象,对象,对象>
{ @覆盖
在preExecute保护无效(){
// TODO自动生成方法存根
super.on preExecute(); 对话框= ProgressDialog.show(DetailActivity.this,,正在加载...); }
@覆盖
保护对象doInBackground(对象... PARAMS){
// TODO自动生成方法存根 馈送= feedParser.parse(); 返回null;
} @覆盖
保护无效onPostExecute(对象结果){
// TODO自动生成方法存根
super.onPostExecute(结果); dialod.dismiss();
date.setText(feeds.get(位置).getTitle());
GetDescriptionWebView.getDescriptionImage(位置,饲料,contentWebView);
titre.setText(Postulé乐:+ GetDateFormat.getDate(位置,饲料)); }}}
I want to show a ProgressDialog when pressing any item of my listview while the Detail class is turning in background, i know that i have to use asyncTask but i can't figure out how, can any one help me please?
This is my fragment where i went to show the ProgressDialog
public class FeedPlayerIndexFragment extends SherlockFragment{
String url="http://www.toto.com/index.php?format=feed&type=rss";
ArrayList<Article> feeds ;
AndroidSaxFeedParser feedParser= new AndroidSaxFeedParser(url);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
feeds=feedParser.parse();
View view=inflater.inflate(R.layout.main, container, false);
CustomItemAdapter_News lfa = new CustomItemAdapter_News(getActivity().getApplicationContext(), feeds);
((ListView)view.findViewById(R.id.listFeed)).setAdapter(lfa);
((ListView)view.findViewById(R.id.listFeed)).setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View v, int position,long id) {
Bundle b = new Bundle();
b.putInt("position", position);
b.putString("url", url);
Intent intent=new Intent(getActivity().getApplicationContext(), DetailActivity.class);
intent.putExtras(b);
startActivity(intent);
}
});
return view;
}
}
This is my Detail Activity whish is supposed to turn on background
public class DetailActivity extends Activity{
String descriptionFinale = null,imageFinale = null,url;
int position;
TextView description_,titre,date;
ImageView image_;
ArrayList<Article> feeds ;
WebView contentWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
Bundle b = getIntent().getExtras();
position=b.getInt("position");
url=b.getString("url");
AndroidSaxFeedParser feedParser= new AndroidSaxFeedParser(url);
feeds=feedParser.parse();
date=(TextView) findViewById(R.id.date);
contentWebView= (WebView)findViewById(R.id.contentWebView);
titre=(TextView) findViewById(R.id.titre);
date.setText(feeds.get(position).getTitle());
GetDescriptionWebView.getDescriptionImage(position, feeds,contentWebView);
titre.setText("Postulé le: "+GetDateFormat.getDate(position, feeds));
}
}
解决方案
You can try this code
public class DetailActivity extends Activity
{
String descriptionFinale = null,imageFinale = null,url;
int position;
TextView description_,titre,date;
ImageView image_;
ArrayList<Article> feeds ;
WebView contentWebView;
ProgressDialog dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
feeds=new Arraylist<Article>;
contentWebView= (WebView)findViewById(R.id.contentWebView);
date=(TextView) findViewById(R.id.date);
titre=(TextView) findViewById(R.id.titre);
Bundle b = getIntent().getExtras();
position=b.getInt("position");
url=b.getString("url");
AndroidSaxFeedParser feedParser= new AndroidSaxFeedParser(url);
new MyFetchTask().execute();
}
public class MyFetchTask extends AsyncTask<Object, Object, Object>
{
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog=ProgressDialog.show(DetailActivity.this, "", "Loading...");
}
@Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
feeds=feedParser.parse();
return null;
}
@Override
protected void onPostExecute(Object result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
dialod.dismiss();
date.setText(feeds.get(position).getTitle());
GetDescriptionWebView.getDescriptionImage(position, feeds,contentWebView);
titre.setText("Postulé le: "+GetDateFormat.getDate(position, feeds));
}
}
}
这篇关于ProgressDialog的Android的AsyncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文