Произошла ошибка в строке состояния Android - PullRequest
0 голосов
/ 11 октября 2011

Я создал приложение для 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);
    }
};

1 Ответ

0 голосов
/ 11 октября 2011

Если вы хотите, чтобы индикатор выполнения отображался в самом первом макете после нажатия кнопки, поместите часть кода XML для индикатора выполнения в этот первый макет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...