0

I am trying to update a TextView by using findViewByID(), but in my onCreate I am calling a layout which does not include the TextView I want to update-they are seperate files.

I have read through the Android Developer Documentation for findViewByID() but I have not found how to find an ID that is not in the same onCreate layout (which means I cannot use R.id.callable_textview).

How can you make findViewById() find the TextView in a seperate layout not called on the onCreate?

try_hard
  • 52
  • 8
  • You'll need to explain more about what your code is doing. Why is this `View` present on the screen if it's not part of the layout specified in `onCreate()`? If it's part of an `` or a dialog box, then that's fine. If it's part of a different `Activity`, then you're on the wrong track. – Gavin Wright Jun 10 '22 at 22:58
  • It is part of a seperate activity. I need to transfer information from one activity to another, where the information is portrayed as a textview in the other activity. – try_hard Jun 10 '22 at 23:01
  • @GavinWright is right what you are trying to do is not permissible that is textview of another activity be updated in another activity. you can pass info within activities but changes in views of an activity is only permissible through that activity – tintin Jun 11 '22 at 05:20

1 Answers1

2

For passing information from Activity A to Activity B, you can use Intent extras. If you need to pass information from Activity B back to Activity A, you can use startActivityForResult().

You shouldn't be trying to access the Views of one Activity from another Activity. That's not how it works.

Gavin Wright
  • 3,124
  • 3
  • 14
  • 35