Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Théo F
1,369 PointsDisplay a layout in function of a variable
Thanks Ben Jakuben for your tuto. I try to do the Blog Reader but in local.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String townNameDev = intent.getStringExtra("town_name_dev");
int resID = this.getResources().getIdentifier(townNameDev, "layout", this.getPackageName());
LinearLayout layout = (LinearLayout)findViewById(resID);
}
I can't do this : //setContentView(R.layout.townNameDev); so I load the ressource but I don't know how to display it. I need to load xml files in function of townNameDev.
Thanks you for your help
2 Answers
Ben Jakuben
Treehouse TeacherThat setContentView() line is very important, so let's start by troubleshooting why that isn't working. When you try to include that line, what error do you get?
Théo F
1,369 PointstownNameDev was a variable but it's stupid to create many layouts just for display differents images. So I do something else. I load my images on an ImageView in a single same layout. Here's https://play.google.com/store/apps/details?id=com.jumpou.Drawy , my app do with your course, if you're curious of what I wanted do ;) Thanks you very much Ben and Treehouse. Please continue, do others android tutorials ! Where you create and use some custom classes ;) A game will be perfect ^^