-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.

4

1 回答 1

1

这解决了它。

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


    int id = getResources().getIdentifier(xmlfile, "layout", getPackageName());
    setContentView(id);
于 2016-05-07T03:05:16.427 回答