Domanda

Sono molto nuovo in Android. Ho avuto due attività a, b. ATTIVITÀ Un anello di analisi dal severo e iterazione attraverso i livelli. e chiama l'attività B attraverso l'intento. L'attività B richiede del tempo per visualizzare i dati, quindi sto cercando di visualizzare la barra di avanzamento. Ecco il mio codice.

 public class Display extends Activity  {

        ProgressDialog dialog;


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.attributequestions);

            new asynctask().execute();


        }

        class asynctask extends AsyncTask<Context,Void,Void>{
            Survey[] surveyque=null;
    // i hace created seperated class forsurvey that has info about data
            String list[];  


            private ProgressDialog Dialog;
            @Override
            protected void onPreExecute()
            {
                Dialog=ProgressDialog.show(Display.this, "Parsing Data", "Please wait..........");


            }
            @Override
            protected void onPostExecute(Void unused)    
            {
                try
                {
                    if(Dialog.isShowing())
                    {
                        Dialog.dismiss();
                    }
                    Intent intent=getIntent();

                }
                catch(Exception e)
                {
    Log.d("Onsitev4", "error");
                }
            }

            @Override
            protected Void doInBackground(Context... params) {
                try {

                    LinearLayout layout1 = (LinearLayout) findViewById(R.id.linearLayout1);

    //getting exception here. I dont understant why
    // I have declared layout params and displaying activities in another class 

                    ButtonView c = new ButtonView();                
                    c.layout=layout1;
                    c.context =getBaseContext();


                    DbCoreSqlSurveys surveys=new DbCoreSqlSurveys(getBaseContext());
                    Document doc =surveys.getSurveySet();
                    surveyquestions= GetSurveyLevels(doc,c );


                } catch (TransformerFactoryConfigurationError e) {
                    e.printStackTrace();
                }
                return null;
            } 

        }

        public SurveyObject[] GetSurveyLevels(Document doc, ButtonView c) {
            NodeList nlQuestions = doc.getElementsByTagName("Survey");
            SurveyObject[] allsurveys = new SurveyObject[nlQuestions.getLength()];


            for (int i = 0; i < nlQuestions.getLength(); i++){

                Node survey =  nlQuestions.item(i);
                String f =survey.getNodeName();
                Log.d("OnsiteV4", "survey " + f);

                NodeList surveyChildNodes = survey.getChildNodes();
                SurveyObject s=new SurveyObject();

                for (int j = 0; j < surveyChildNodes.getLength(); j++){

                    Node surveyChild =  surveyChildNodes.item(j);               
                    String h =surveyChild.getNodeName();
                    Log.d("OnsiteV4", "survey child node = " + h);

                    if (h !="#text"){
                        Surveys t = Surveys.valueOf(h); 

                        switch(t){
                        case KeySurvey:
                            s.KeySurvey=surveyChild.getTextContent();
                            displaySurveyLink(s.SurveyDescription,"",c,0,s.SurveyDescription,"","","","");
                            break;
                        case SurveyDescription:
                            s.SurveyDescription=surveyChild.getTextContent();
                            displaySurveyLink(s.SurveyDescription,"",c,0,s.SurveyDescription,"","","","");
                            break;
                        case SurveyUserCode:
                            s.SurveyUserCode=surveyChild.getTextContent();
                            break;
                        case Level1:
                            if(surveyChild.hasChildNodes()){
                                s.Level1=   processLevel1Nodes(surveyChild,c,s.SurveyDescription);
                            }
                            break;
                        default:
                            break;
                        }
                    }

                    allsurveys[i]=s;
                }
            }

            return allsurveys;
        }

    // methods iterating through levels that is not showed

        private  void displaySurveyLink(final String description, String tag, ButtonView c, int indentation, final String surveyDescription, final String level1description, final String level2description, final String level3description, final String level4description)
        {
            if (description == null || tag == null){
                return;
            }
            final TextView tv = c.addButton(description,tag,indentation);


            tv.setOnClickListener(new OnClickListener(){
                public void onClick(View v) {

                    final Intent intent = new Intent();
                    intent.setClass(v.getContext(),ActivityB.class);
                    intent.putExtra("KeyLevel",tv.getTag().toString()); 

                    intent.putExtra("SurveyDescription",surveyDescription);
                    intent.putExtra("level1description",level1description);
                    intent.putExtra("level2description",level2description);
                    intent.putExtra("level3description",level3description);
                    intent.putExtra("level4description",level4description);
                    intent.putExtra("Description",description);

                    if (tv.getTag() != null){
                        if (tv.getTag().toString() != ""){
                            startActivity(intent);
                        }


                    }
                }


            });
        }
    }  

Ricevo un'eccezione a Doinbackground. Sono confuso . mi aiuti per favore..

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top