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,901
  • 21
  • 84
  • 115
Paul
  • 3,644
  • 9
  • 47
  • 113

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
  • 20,406
  • 11
  • 52
  • 83
Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
  • 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