0

i got a textview which should changes the text after the intent (directorypicker) finish.that doesn't work. heres the code:

text = (TextView) findViewById(R.id.choose3);
        text.setText(globalconstant.path);

should change the text when the intent returns the path:

private void addListenerOnButton() {
        choose_button = (Button) findViewById(R.id.button1);
        choose_button.setEnabled(true);
        choose_button.setOnClickListener(new OnClickListener() {
            public void onClick(View arg0) {
                // DirectoryPicker.START_DIR = "/mnt/";
                Intent intent = new Intent(settings.this, DirectoryPicker.class);
                startActivityForResult(intent, DirectoryPicker.PICK_DIRECTORY);
                // text.setText(globalconstant.path);
                text = (TextView) findViewById(R.id.choose3);
                text.setText(globalconstant.path);
                ;

            }
        });

    }

whats wrong with it? please help me! Thank you very much

david
  • 89
  • 11

3 Answers3

3

Probably, you should change the text in onActivityResult

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
0

First test if you code work, replace text.setText(globalconstant.path); with text.setText("Test message"); is this work or not.

Then you can add a Log.d("TestAfterStartAct", "Test Message") open the commandos line and run adb logcat for show the log from the phone. Try to note while is the code run, before/after/never after the new Activity is show?

Some times you can get error with no updates GUI parts if the edit not is do from a UI thread, call for you text.postInvalidate() for update the GUI for the textview.

Read more on What does postInvalidate() do?

Community
  • 1
  • 1
FIG-GHD742
  • 2,486
  • 1
  • 19
  • 27
0

I had the same problem. The issue for me was that onStart is called when after onActivityResult was called. In the onStart I was inflating the view which was creating a new textview, with the default values.

In my case I solved it by saving the values in the onActivityResult and then apply the values in the onStart function.
-James

James Becwar
  • 1,176
  • 2
  • 11
  • 20