2011-10-11 16 views
-1

Androidアプリケーションを作成しました。そのプログラムでは、2つのレイアウトがあります。最初のレイアウトでボタンをクリックすると、2番目のレイアウトがプログレスバーとともに表示されます。私の問題は、ボタンをクリックした後、進捗バーが最初のレイアウトに配置されることです。この問題を解決するにはどうすればよいですか?あなたはプログレスバーが、その後、ボタンのクリック後の最初のレイアウト自体に表示される最初のレイアウトにプログレスバーのコードのXMLの一部を配置する場合Androidの進行状況バーでエラーが発生しました

// Get the increment value from the text box 
myTitleText = (EditText) findViewById(R.id.editText1); 
s = myTitleText.getText().toString(); 

con=myTitleText.length(); 

//Convert the textvalue to a integer value 
dialog = new ProgressDialog(this); 
dialog.setCancelable(true); 
dialog.setMessage("Loading..."); 

// Set the progress to be horizontal 
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); 

// Reset the bar to the default value of 0 
dialog.setProgress(0); 

// Get the maximum value 
int maximum=jstr.length(); 

// Set the maximum value 
dialog.setMax(maximum); 

// Display the progress bar 
dialog.show(); 

// Create a thread for updating the progress bar 
Thread background = new Thread (new Runnable() { 
    public void run() { 
     try { 
      // Enter the code to be run while displaying the progress bar. 
      // 
      // This example is just going to increment the progress bar: 
      // So keep running until the progress value reaches maximum value 
      while (dialog.getProgress()<= dialog.getMax()) { 
       // Wait 500 ms between each update. 
       Thread.sleep(500); 

       // Activate the update handler 
       progressHandler.sendMessage(progressHandler.obtainMessage()); 
      } 
     } 
     catch (java.lang.InterruptedException e) { 
      // If something fails, do something smart 
     } 
    } 
}); 

// Start the background thread 
background.start(); 

// Handler for the background updating 
progressHandler = new Handler() { 
    public void handleMessage(Message msg) { 
     dialog.incrementProgressBy(con); 
    } 
}; 
+0

よろしいですか?エラーは何ですか? – user370305

+0

私は2番目のレイアウトでプログレスバーを取得しました。しかし、私は最初のレイアウトでそれをしたい –

答えて

0

は、ここに私のコードです。

関連する問題