2012-03-13 7 views
0

私は1つのレイアウトを持ち、2つの異なるインスタンスを表示するために使用します。以下のコードを見てください。私はこのロジックがうまくいくはずですが、動作していないと思います。いつかレイアウトを拡張する方法は?

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

私が通常この問題を処理する方法は、両方のインスタンスを共通の親レイアウトを持つ別々のレイアウトに展開することです。次に、バッテリの状態(またはその他のもの)に応じて、私が表示したいレイアウトの可視性をプログラムで切り替えることができます。一方のレイアウトは常にVISIBLEになり、他方のレイアウトは常にGONEになります。

関連する問題