First create a class file not an activity and extend it with linearlayout
This will create your custom view .
Now lets suppose the package of your custom view is org.customView and class
is mylayoutfile.class
Then in the main.xml you can add this layout file just as you add a button,
textview or any widget but the important thing is how to write the name of
the widget.
Name of the widget will be the complete name of your custom view java file
like :-
<org.customView.mylayoutfile android:id=""
android:layout_width=""............... />
instantiate this id in your main class
Dont forget to add constructors like :-
public NavigationBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NavigationBar(Activity context) {
super(context);
}
This will be it now you just need to know how to iniflate it in your custom
view class :)
On Wed, Apr 13, 2011 at 10:27 PM, usher <[email protected]> wrote:
> So I have created this activity, and setContentView() with mail.xml
> layout file.
> Now I want to add some textView dynamically into this screen. I
> already have these text view defined in a seperate xml file named
> view.xml.
>
> How can I instantiate these textview components and add them into
> screen?
>
> I know we have inflate method, but once we call inflate, this view.xml
> will be added to screen automatically....how can we achieve this?
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en