在Android的这一计划没有检索XML数据后,进度条加载帮我 [英] In android this program not retrieve the xml data after the progress bar loading help me

查看:171
本文介绍了在Android的这一计划没有检索XML数据后,进度条加载帮我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

\\ Android中programming..i喜欢在我想,直到数据检索xmltags加载进度同时从URL(xmlparsing)检索的数据xmltags的。我附上我的code检的仪式或错误是否谢谢\\

  \\\\的主要活动\\\\
公共类的行为扩展活动
{ \\\\使用按钮点击后启动功能\\\\    按钮B;
    公共ProgressDialog支持mDialog;
    @覆盖
     公共无效的onCreate(捆绑savedInstanceState){        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);        B =(按钮)findViewById(R.id.button1);
        b.setOnClickListener(新OnClickListener(){            公共无效的onClick(视图v){
                // TODO自动生成方法存根
                新GetTask()执行();            }
        });
}
   我\\\\ \\\\的AsyncTask类GetTask扩展的AsyncTask<对象,太虚,字符串>
{    @覆盖
    在preExecute保护无效()
    {
        super.on preExecute();         支持mDialog =新ProgressDialog(act.this);
         mDialog.setMessage(请稍候...);
         mDialog.show();
    }
     @覆盖
    保护字符串doInBackground(对象... PARAMS)
    {  \\\\ UI programetically声明textviews \\\\                 尝试{
                    的LinearLayout布局=新的LinearLayout(act.this);
                    layout.setOrientation(1);
                    TextView中没有[];
                    TextView的NA []​​;
                    TextView的C [];
                  网址URL =新的URL(http://api.androidhive.info/pizza/?format=xml);
                  DBF的DocumentBuilderFactory = DocumentBuilderFactory.newInstance();
                  的DocumentBuilder分贝= dbf.newDocumentBuilder();
                  文档的文档= db.parse(新的InputSource(url.openStream()));
                  doc.getDocumentElement()正常化()。
                  节点列表节点列表= doc.getElementsByTagName(项目);
                  无=新的TextView [nodeList.getLength()];
                  NA =新的TextView [nodeList.getLength()];
                  C =新的TextView [nodeList.getLength()];                  的for(int i = 0; I< nodeList.getLength();我++){
                      节点node = nodeList.item(ⅰ);
                      没有[I] =新的TextView(act.this);
                      呐[I] =新的TextView(act.this);
                      C [i] =新的TextView(act.this);
                      元素fstElmnt =(元素)节点;                      节点列表IDLIST = fstElmnt.getElementsByTagName(ID);
                      元件numelement =(元件)idlist.item(0);
                      IDLIST = numelement.getChildNodes();
                      无[I] .setText(ID =+((节点)idlist.item(0))getNodeValue());                      节点列表名称列表= fstElmnt.getElementsByTagName(名称);
                      元件namelement =(元件)namelist.item(0);
                      名称列表= namelement.getChildNodes();
                      呐[I] .setText(比萨NAME =+((节点)namelist.item(0))getNodeValue());                      节点列表costlist = fstElmnt.getElementsByTagName(代价);
                      元件costlement =(元件)costlist.item(0);
                      costlist = costlement.getChildNodes();
                      C [I] .setText(成本=+((节点)costlist.item(0))getNodeValue());                      layout.addView(无[I])​​;
                      layout.addView(NA [I]);
                      layout.addView(C [I]);
                      的setContentView(布局);                      }}
             赶上(例外五){
                     }
        返回null;            }            @覆盖
    保护无效onPostExecute(字符串结果)
    {
        super.onPostExecute(结果);
        mDialog.dismiss();            }
   }
  }


解决方案

下面code是错误的。

ü不要在你的onPostExecute任何数据(),所以无论YOUE要显示只是显示在onPostExecute(那件事),而不是doInBackground()。

所以改变它。

一个样本为例u能找到在惰性加载或者AsyncTask的应用程序: -

  https://github.com/thest1/LazyListhttps://github.com/ethervoid/android-async-task-example

五月与以下code u能得到乌尔ANS ...... !!!!

\In android programming..i like to retrieve data's in the xmltags from url(xmlparsing) in the meantime i want to load progress until the data retrieve from xmltags. i attach my code check whether its rite or wrong thank you\

 \\main activity\\


public class act extends Activity
{

 \\button used to start the function after the click\\

    Button b;
    public ProgressDialog mDialog;
    @Override
     public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        b=(Button)findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                new GetTask().execute();

            }
        });
}
   \\my asynctask\\

class GetTask extends AsyncTask<Object, Void, String>
{



    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();

         mDialog = new ProgressDialog(act.this);
         mDialog.setMessage("Please wait...");
         mDialog.show();
    }
     @Override
    protected String doInBackground(Object... params)
    {

  \\ui programetically declare the textviews\\

                 try {
                    LinearLayout layout = new LinearLayout(act.this);
                    layout.setOrientation(1);
                    TextView no[];
                    TextView na[];
                    TextView c[];


                  URL url = new URL("http://api.androidhive.info/pizza/?format=xml");          
                  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();          
                  DocumentBuilder db = dbf.newDocumentBuilder();
                  Document doc = db.parse(new InputSource(url.openStream()));
                  doc.getDocumentElement().normalize();
                  NodeList nodeList = doc.getElementsByTagName("item");
                  no = new TextView[nodeList.getLength()];
                  na = new TextView[nodeList.getLength()];
                  c = new TextView[nodeList.getLength()];

                  for (int i = 0; i < nodeList.getLength(); i++) {
                      Node node = nodeList.item(i);
                      no[i] = new TextView(act.this);
                      na[i] = new TextView(act.this);
                      c[i] = new TextView(act.this);
                      Element fstElmnt = (Element) node;

                      NodeList idlist = fstElmnt.getElementsByTagName("id");
                      Element numelement = (Element) idlist.item(0);
                      idlist = numelement.getChildNodes();
                      no[i].setText("ID="+ ((Node) idlist.item(0)).getNodeValue());

                      NodeList namelist = fstElmnt.getElementsByTagName("name");
                      Element namelement = (Element) namelist.item(0);
                      namelist = namelement.getChildNodes();
                      na[i].setText("pizza name="+ ((Node) namelist.item(0)).getNodeValue());

                      NodeList costlist = fstElmnt.getElementsByTagName("cost");
                      Element costlement = (Element) costlist.item(0);
                      costlist = costlement.getChildNodes();
                      c[i].setText("cost="+ ((Node) costlist.item(0)).getNodeValue());

                      layout.addView(no[i]);
                      layout.addView(na[i]);
                      layout.addView(c[i]);
                      setContentView(layout);

                      }} 
             catch (Exception e) {
                     }
        return null;

            }

            @Override
    protected void onPostExecute(String result)
    {
        super.onPostExecute(result);
        mDialog.dismiss(); 

            }
   }
  }

解决方案

The Following code is Wrong.

U dont have any data in your onPostExecute() so whatever youe want to display just show that thing in onPostExecute() instead of doInBackground().

So change it ..

A sample example u can find in LazyLoading Or Asynctask App:-

https://github.com/thest1/LazyList

https://github.com/ethervoid/android-async-task-example

May with following code u can get ur ans...!!!!

这篇关于在Android的这一计划没有检索XML数据后,进度条加载帮我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆