【发布时间】:2011-10-11 06:53:31
【问题描述】:
我创建了一个 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);
}
};
【问题讨论】:
-
我在第二个布局中获得了进度条。但我希望它在第一个布局中
标签: android progress-bar