iman453
iman453

Reputation: 9565

Can I create a layout using the xml file and code within the activity?

I've just started playing around with android, so pardon me if this is a totally stupid question.

I'm trying to create a simple text based game in which I ask a question based on a movie. The list of movie's is in a text file which I've included in res/raw. So basically I want to have a default string, say "Who acted in", followed by the name of the movie. Could I have the first string (along with a submit button etc) in my res/layout/main.xml file, and follow that with the movies name, after I've extracted it from the text file in my activity, or does the layout have to be defined in one place only?

Thanks..

Upvotes: 1

Views: 273

Answers (1)

Pentium10
Pentium10

Reputation: 208002

Yes you can mix these things. You will tell your activity to use the view based on XML.

Then you will create a TextView object(or whatever is your question made of), and use the findViewById method to get the object. Then simply call setText(newText) on it and you are done.

Upvotes: 1

Related Questions