1

I have the following function: createEl(View view, ....)

I have to go to the same View function I'm using in the:

setContentView(R.layout.activity_main).

I tried with:

View view = (View) getLayoutInflater().Inflate (R.layout.activity_main, null);

But it does not work. How can I do?

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
Paul
  • 2,570
  • 5
  • 26
  • 72

1 Answers1

3

Your code isn't working because you are using different instances of the layout. Inflate the view and use that in setContentView().

Try this

View view =  getLayoutInflater().inflate (R.layout.activity_main, null);
setContentView(view);

Now you can use view the way you want. It would be the same instance which is loaded in the activity.

ADM
  • 18,477
  • 11
  • 47
  • 78
Rohit5k2
  • 17,529
  • 8
  • 42
  • 56
  • There are other methods to get the loaded view but this should suit you best. see this https://stackoverflow.com/questions/5273436/how-to-get-activitys-content-view – Rohit5k2 Nov 15 '18 at 12:36