0

I have an EditText in my MainActivity. When the user clicks the NewFile activity the layout for this activity is transparent so the EditText can still be seen. I want to be able to update the EditText in the background from the NewFile activity. This is what I've tried, which results in a NullPointerException. I understand why this didn't work but what can I do instead to get the results I'm looking for.

NewFile.java

protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newfile);

        newet = (EditTextLineNumbers) findViewById(R.id.ide);
        newet.setText("Testing");
    }
RapsFan1981
  • 1,177
  • 3
  • 21
  • 61
  • If I understood the question right, you mean you want to modify the content of a texteditor in a different activity from another activity. if that's the case take a look at [Link](http://stackoverflow.com/questions/4909354/change-text-from-other-activity?rq=1) . the bottom line is it is not a good practice even if possible. P.S. Please remove android from title, the android tag is a good indicator! – Saeid Farivar Feb 16 '13 at 19:16
  • Thanks Saeid and I won't put Android in my question titles from now on :) Good to know. – RapsFan1981 Feb 16 '13 at 19:32

3 Answers3

1

How did you think it will work..? How do you access the view which is not in your activity layout..? To say it is not possible...

You can get the EditText of your previous layout by using the layout inflatter service to your layout and from that your view

Pragnani
  • 20,075
  • 6
  • 49
  • 74
1

Your background EditText is not from the layout currently set for the user, thus you are getting the exception.

Regarding updating the UI, 2 things you might need.

  1. Pass the handler of the background activity to the new one
  2. Make the new one as a dialog rather than a transparent activity.
  3. Use the handler to send notifications and update the UI accordingly
rock_win
  • 755
  • 1
  • 5
  • 14
1

In the NewFile activity, have an edit text which overlays your transparent editTextView(may be have a transparent BG for this textview which might give illusion that its in background), now update this editTextView
and
once you go back, take data from this edittext(using setActivityForResult and those mechanisms) and fill in the previous activity.

sat
  • 40,138
  • 28
  • 93
  • 102