2012-03-13 26 views
0

我有一個佈局,我用它來顯示兩個不同的實例。請參閱下面的代碼,我想這個邏輯應該可以工作,但它不工作。如何膨脹一個佈局一段時間,然後另一個?

setContentView(R.layout.notification); 
//Notify user if Battery level is low 
     if (iBatlevel <= 50) 
     { 

      ImageButton CamButton = (ImageButton) findViewById(R.id.imageButton2); 
      CamButton.setVisibility(View.GONE); 
      ImageButton PButton = (ImageButton) findViewById(R.id.imageButton1); 
      PButton.setVisibility(View.GONE); 
      ProgressBar _batPB = (ProgressBar) findViewById(R.id.progressBar); 
      _batPB.setProgress(iBatlevel); 
      _batPB.setVisibility(View.VISIBLE); 
      TextView _batText = (TextView) findViewById(R.id.notifymsg); 
      _batText.setText("!!! Low Battery !!!\n"+Integer.toString(iBatlevel)+"%"+" remaining"); 

      //Wait for 4 seconds 
      Handler handler = new Handler(); 
      handler.postDelayed(new Runnable() { 
       public void run() {      
       } 
      }, 400000); 
     } 
     /*****************************************************************************************/ 


     //To check whether SDcard is present are not 
     boolean isSDCardPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); 
    // Intent intent = null; 
     if(isSDCardPresent) 
     { 
     // setContentView(R.layout.sdcard); 
      ImageButton CamButton = (ImageButton) findViewById(R.id.imageButton2); 
      CamButton.setVisibility(View.VISIBLE); 
      ImageButton PButton = (ImageButton) findViewById(R.id.imageButton1); 
      PButton.setVisibility(View.VISIBLE); 

      ProgressBar _batPB = (ProgressBar) findViewById(R.id.progressBar); 
      _batPB.setVisibility(View.GONE); 
      Drawable warning_img = getApplicationContext().getResources().getDrawable(R.drawable.warning); 
      TextView warning = (TextView) findViewById(R.id.notifymsg); 
      warning.setText("SDcard not found !!!"); 
      warning_img.setBounds(0, 0, 30, 30); 
      warning.setCompoundDrawables(warning_img, null, null, null); 

      // intent = new Intent(this,SDcard.class); 
      // startActivity(intent); 
      // finish(); 
     } 

如果電池電量低,相應的佈局應該會顯示一段時間,然後其他,但儘管電池循環是真的,我只得到了SD卡視圖。任何想法如何去?

回答

0

我通常如何處理這個問題是將兩個實例充氣到具有共同父佈局的單獨佈局。然後以編程方式切換要顯示的佈局的可見性,具體取決於電池狀態(或其他)。一個佈局將始終可見,而另一個佈局將始終爲GONE。