user335518
user335518

Reputation: 121

Android: add new view with a XML Layout file

I am beginning developing android application. What I need to know is how to associated a xml layout file with a new class (not the activity). For example the class needs to have a table with an image and some texts.

thanks!

Upvotes: 4

Views: 6345

Answers (3)

Rohit Heera
Rohit Heera

Reputation: 2727

You can also write this like:

LayoutInflater inflator = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflator.inflate(R.layout.yourxmllayout, null);

If you are in activity there is no need to use context.

Upvotes: 0

catalin87
catalin87

Reputation: 623

Got the answer try this:

LayoutInflater inflater = LayoutInflater.from(context);
         View v = inflater.inflate(R.layout.yourxmllayout, null, false);

Upvotes: 4

Tyler
Tyler

Reputation: 22116

You mean like this? http://developer.android.com/guide/topics/ui/custom-components.html

Upvotes: -1

Related Questions