加载微调器未正确显示

时间:2014-04-14 09:28:06

标签: android spinner android-spinner android-ui

我正在尝试在我的数据加载和UI更新时放置一个微调器,所以对于这个任务,我这样做:

protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_road_details);     
    setTitle("Details");


    startButt = (Button)findViewById(R.id.BeginJourney);    
    Map = (Button)findViewById(R.id.map_btn1);

    boolean GreenButtState = getIntent().getBooleanExtra("GreenButtState", false);
    boolean FastButtonState = getIntent().getBooleanExtra("FastButtonState", false);


  AsyncTask<Void, Void, Void> LoadingTask = new AsyncTask<Void, Void, Void>() 
  { 
      ProgressDialog dialog = new ProgressDialog(RoadDetails.this);
      @Override
        protected void onPreExecute()
       {
          this.dialog.setMessage("Message");
          this.dialog.show();
       }


        @Override
        protected Void doInBackground(Void... params)
        {    
            final HashMap<String, Object> trip1;

            Intent intent = getIntent();            
            mXmlRpcUrl = intent.getStringExtra("XmlRpcUrl");
            mSessionID = intent.getStringExtra("SessionID");
            mGetSavedTripFunc = intent.getStringExtra("GetSavedTripFunc");
            newTripID = intent.getIntExtra("newTripID", 0);
            variantID = intent.getIntExtra("VariantID", 0);
            Week = intent.getIntExtra("WeekState", 0);
            CityName = intent.getStringExtra("NameOfCity");
            Flag = intent.getIntExtra("Flag", 0);
            startLatitude = intent.getDoubleExtra("startLatitude", 0.0);
            startLongitude = intent.getDoubleExtra("startLongitude", 0.0);
            endLatitude = intent.getDoubleExtra("endLatitude", 0.0);
            endLongitude = intent.getDoubleExtra("endLongitude", 0.0);

            trip1 = (HashMap<String, Object>) intent.getSerializableExtra("Variant");
            variant = new Variant();
            variant.Read(trip1);    

            startButt.setOnClickListener(new OnClickListener() 
            {

                @Override
                public void onClick(View v) 
                {
                    Intent intent = new Intent(RoadDetails.this, Localisation.class);
                    intent.putExtra("SessionID", mSessionID);
                    intent.putExtra("XmlRpcUrl", mXmlRpcUrl);
                    intent.putExtra("NewTripID", newTripID);
                    intent.putExtra("VariantID", variantID);
                    intent.putExtra("WeekState", Week);
                    intent.putExtra("NameOfCity", CityName);
                    intent.putExtra("Variant", (Serializable)trip1);
                    intent.putExtra("Flag", Flag);
                    intent.putExtra("startLatitude", startLatitude);
                    intent.putExtra("startLongitude", startLongitude);
                    intent.putExtra("endLatitude", endLatitude); 
                    intent.putExtra("endLongitude",endLongitude);                                   
                    startActivity(intent);          
                }
            });

            Map.setOnClickListener(new OnClickListener()
            {           
                @Override
                public void onClick(View v) 
                {
                    //Intent intent1 = new Intent (RoadDetails.this, MapDraw.class);
                    Intent intent1 = new Intent (RoadDetails.this, OSMActivity.class);
                    intent1.putExtra("SessionID",mSessionID);
                    intent1.putExtra("endLatitude", endLatitude); 
                    intent1.putExtra("endLongitude",endLongitude);
                    intent1.putExtra("startLatitude", startLatitude);
                    intent1.putExtra("startLongitude", startLongitude);
                    intent1.putExtra("Variant", (Serializable)trip1);
                    startActivity(intent1);
                }
            });
            return null;
        }

        @Override
        protected void onPostExecute(Void result) 
        {
            GettingData();
            this.dialog.dismiss();              
        }
    };       

    LoadingTask.execute((Void[])null);       
}

然而,当我这样做时,在打开包含此代码的活动之前有一个延迟(我希望微调器在加载数据时在那里),微调器没有显示。只有一个延迟(对于要加载的数据 - 让它也称为屏幕冻结1 - 3秒)就是这样。我究竟做错了什么?我希望微调器在数据加载时显示,然后在此之后被解除。我在方法GettingData()中还提到了什么;我正在更改UI - 动态添加布局,添加图像等。

2 个答案:

答案 0 :(得分:0)

编写ProgressDialog对话框;在AsyncTask之外

致电

       dialog = new ProgressDialog(RoadDetails.this);

      dialog.setMessage("Message");
      dialog.show();

在onPreExecute()中。

希望它会帮助你..

答案 1 :(得分:0)

试试这个...这将有效

  ProgressDialog dialog = new ProgressDialog(RoadDetails.this);

   this.dialog.setMessage("Message");
   this.dialog.show();

//start your asynchronous task here

     load your data here

//end asynchronous task

 this.dialog.dismiss();