-4

My app has a method that uses

setContentView(R.layout.activity_deashibarai);

to set the view of the activity.

But i would like that the xml file name (in this case, activity_deashibarai) to be passed as a variable. I have a string variable to store that variable.

setContentView(R.layout.variable) does not work.

John Paul
  • 12,196
  • 6
  • 55
  • 75
yurividal
  • 167
  • 7

1 Answers1

1

This Solved it.

    Bundle extras = getIntent().getExtras();
    String xmlfile = null;
    if (extras != null) {
        xmlfile = extras.getString("xmlfile");
    }


    int id = getResources().getIdentifier(xmlfile, "layout", getPackageName());
    setContentView(id);
yurividal
  • 167
  • 7