4

This is probably a trivia question, but why are there package/class names in some people's XML layout files?

(please don't downvote this question if it is something trivial, i don't even know what this is called, so i couldn't look it up).

i was looking at a tutorial, and i saw something like this (in "sample.xml"):

<com.tutorials.foo android:layout_width="match_parent" android:layout_height="match_parent" > <!-- some buttons and views here --> </com.tutorials.foo> 

My questions are:

1) i'm assuming that "foo" is a custom view? say, like you want to extend TextView with your own version of TextView?

2) what is this pattern/technique even called?

3) what would be the advantages of using this method?

Thanks so much in advance!!!

1 Answer 1

1
  1. Yes, <com.tutorials.foo .../> is a custom view.
  2. Calling it will be as same as others.ex:

    Foo foo=(Foo)findViewById(R.id.foo);

  3. I assume you mean creating layout static(.xml) or dynamically with code. xml layout would be in advantage when you know that you will use this layout in the program and will not change its format. Of course you can add to it or edit it with code later on. It is also in advantage for readabilty.

Sign up to request clarification or add additional context in comments.

1 Comment

1) gotcha. 2) i meant what the technique is called, like what is it's name? 3) i didn't understand that this is a custom view, to which you can now say... subclass TextView to have a special font, and if your app has 50 of these subclassed textviews, you don't have to go find every textview and change their font later

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.