Reputation: 17743
I have button and onClick I perform opening of a new activity like this:
Intent myIntent1 = new Intent(this, B.class);
startActivity(myIntent1);
is there any way in this step to attach to newly opened activity layout I want? B class would be used a lot in my app and for each instance I need to have separate XML layout
Thanks for reply
Hmyzak
Upvotes: 2
Views: 7074
Reputation: 36035
Pass in the ID of the layout you want via extra
Something like this:
Intent myIntent1 = new Intent(this, B.class);
myIntent1.putExtra("layout", R.layout.myLayout);
startActivity(myIntent1);
Then in the Activity have this:
Bundle parameters = getIntent().getExtras();
if(parameters != null && parameters.containsKey("layout"))
setContentView(parameters.getInt("layout"));
else
setContentView(R.layout.defaultLayout);
Upvotes: 3
Reputation: 24021
pass condition variable
thru intent
and on activity
set layout as per your variable value...
Upvotes: 1