Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ProgressDialog Android异步任务_Java_Android_Android Asynctask_Progressdialog - Fatal编程技术网

Java ProgressDialog Android异步任务

Java ProgressDialog Android异步任务,java,android,android-asynctask,progressdialog,Java,Android,Android Asynctask,Progressdialog,我想在按下listview的任何项时显示一个ProgressDialog,而Detail类在后台打开,我知道我必须使用asyncTask,但我不知道如何使用,有人能帮我吗 这是我用来展示ProgressDialog的片段 public class FeedPlayerIndexFragment extends SherlockFragment{ String url="http://www.toto.com/index.php?format=feed&type=rss"

我想在按下listview的任何项时显示一个ProgressDialog,而Detail类在后台打开,我知道我必须使用asyncTask,但我不知道如何使用,有人能帮我吗

这是我用来展示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;
}
} 
公共类FeedPlayerIndexFragment扩展了SherlockFragment{
字符串url=”http://www.toto.com/index.php?format=feed&;类型=rss”;
ArrayList提要;
AndroidSaxFeedParser feedParser=新的AndroidSaxFeedParser(url);
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//TODO自动生成的方法存根
feeds=feedParser.parse();
视图=充气机。充气(R.layout.main,容器,假);
CustomItemAdapter\u News lfa=新的CustomItemAdapter\u新闻(getActivity().getApplicationContext(),提要);
((ListView)view.findviewbyd(R.id.listFeed)).setAdapter(lfa);
((ListView)view.findViewById(R.id.listFeed)).setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView arg0,视图v,内部位置,长id){
Bundle b=新Bundle();
b、 putInt(“位置”,位置);
b、 putString(“url”,url);
意向意向=新意向(getActivity().getApplicationContext(),DetailActivity.class);
意向.附加条款(b);
星触觉(意向);
}
});
返回视图;
}
} 
这是我的细节活动,应该在后台打开

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));

}

}
public类DetailActivity扩展活动{
String descriptionFinale=null,imageFinale=null,url;
内部位置;
文本视图描述、标题、日期;
图像视图图像;
ArrayList提要;
网络视图内容网络视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
Bundle b=getIntent().getExtras();
位置=b.getInt(“位置”);
url=b.getString(“url”);
AndroidSaxFeedParser feedParser=新的AndroidSaxFeedParser(url);
feeds=feedParser.parse();
日期=(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(位置、提要、内容WebView);
titre.setText(“postureéle:+GetDateFormat.getDate(position,feed));
}
}
您可以尝试此代码

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));

    }

}

}
public类DetailActivity扩展活动
{
String descriptionFinale=null,imageFinale=null,url;
内部位置;
文本视图描述、标题、日期;
图像视图图像;
ArrayList提要;
网络视图内容网络视图;
进程对话;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
feed=新的Arraylist;
contentWebView=(WebView)findViewById(R.id.contentWebView);
日期=(TextView)findViewById(R.id.date);
titre=(TextView)findViewById(R.id.titre);
Bundle b=getIntent().getExtras();
位置=b.getInt(“位置”);
url=b.getString(“url”);
AndroidSaxFeedParser feedParser=新的AndroidSaxFeedParser(url);
新建MyFetchTask().execute();
}
公共类MyFetchTask扩展了AsyncTask
{
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
dialog=ProgressDialog.show(DetailActivity.this,“,”加载…);
}
@凌驾
受保护对象doInBackground(对象…参数){
//TODO自动生成的方法存根
feeds=feedParser.parse();
返回null;
}
@凌驾
受保护的void onPostExecute(对象结果){
//TODO自动生成的方法存根
super.onPostExecute(结果);
dialod.discouse();
date.setText(feeds.get(position.getTitle());
GetDescriptionWebView.getDescriptionImage(位置、提要、内容WebView);
titre.setText(“postureéle:+GetDateFormat.getDate(position,feed));
}
}
}

这是异步任务的一个示例,希望能有所帮助

  class NewCouponsTask extends AsyncTask<String, Void, ArrayList<NewCoupons>>

 {
NewCouponsScreen parentActivity;

public NewCouponsTask(NewCouponsScreen parent) {
    // TODO Auto-generated constructor stub
    parentActivity = parent;
}

@Override
protected void onPreExecute() {
    // TODO Auto-generated method stub
    super.onPreExecute();
}
@Override
protected ArrayList<NewCoupons> doInBackground(String... params) {

    URL url=null;
    ArrayList<NewCoupons> couponslist=null;
    try {
        url = new URL(ApplicationLinks.newCouponsLink);

     InputSource is = new InputSource(url.openStream());
     is.setEncoding("UTF-8");
    SaxFeedParser saxParser = new SaxFeedParser(ApplicationLinks.newCouponsLink);
    Log.e("Error",ApplicationLinks.newCouponsLink);
    couponslist=saxParser.parse();  
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return couponslist;
}

@Override
protected void onPostExecute(ArrayList<NewCoupons> result) {
    // TODO Auto-generated method stub
    parentActivity.fetchNewCoupons(result);
        }

}
class NewCouponsTask扩展了AsyncTask
{
NewCouponsScreen父活动;
公共NewCoupOnTask(NewCoupOnScreen父级){
//TODO自动生成的构造函数存根
家长活动=家长;
}
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
}
@凌驾
受保护的ArrayList doInBackground(字符串…参数){
URL=null;
ArrayList couponslist=null;
试一试{
url=新url(ApplicationLinks.newCouponsLink);
InputSource is=新的InputSource(url.openStream());
is.setEncoding(“UTF-8”);
SaxFeedParser saxParser=新的SaxFeedParser(ApplicationLinks.newCouponsLink);
Log.e(“错误”,ApplicationLinks.newCouponsLink);
couponslist=saxParser.parse();
}捕获(例外e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回耦合列表;
}
@凌驾
受保护的void onPostExecute(ArrayList结果){
//TODO自动生成的方法存根
parentActivity.FetchNewCultons(结果);
}
}
您可以在中加载progressbar onPreExecute() 功能 把它停下来 onPostExecute()
函数

您现在是否已解决问题,或者需要帮助解决问题???您希望在DetailActivity类中显示进度对话框???否我在onItemClick上的FeedPlayerIndexFragment中启动进度对话框,并在准备显示DetailActivity类时将其关闭。我认为您正在从DetailActivity类中的url获取数据,所以您必须在DetailActivity类中显示对话框。我正在写代码作为回答,你们可以试试那个代码。我需要这样的东西谢谢:))这很有帮助,但我有11个片段,我需要调用所有片段的详细活动类!