java - How do I link a View class to the XML screen? -
i still learning java , how use eclipse have xml main activity file (the graphical layout) , java file named mainscreen extends activity.
inside mainscreen file have class named myview extends view , can display on device screen calling setcontentview(new myview(this));
mainscreen oncreate method. how make can have myview view within xml file?
i can change setcontentview(r.layout.activity_main_screen);
and sets xml file how have both displayed.
i want display screen if following setcontentview(r.layout.activity_main_screen);
layout have myview displayed inside seperate view on screen. have tried setting setcontentview(r.id.view1);
if being honest not 100% sure doing still learning.
can please point me in right direction or me out? have been googling trying figure out , i'm little lost.
thanks
edit: added code below
xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".mainscreen" > <imageview android:id="@+id/imageview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_margintop="20dp" android:contentdescription="@string/hello_world" android:src="@drawable/title_plate" /> <view android:id="@+id/view1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/imageview1" android:layout_centerhorizontal="true" /> </relativelayout>
the start of myview class
public class myview extends view { public myview(context context) { super(context); //setcontentview(r.id.view1); setcontentview(r.layout.activity_main_screen);
the oncreate main file itself
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //setcontentview(r.layout.activity_main_screen); setcontentview(new myview(this)); //view circleview = (view)findviewbyid(r.id.view1); //circleview = (new myview(this)); //circleview = findviewbyid(r.id.view1); }
i won't post other stuff file contains seem pretty pointless code want do.
take class view class
package com.example.utils.views; import android.content.context; import android.graphics.typeface; import android.util.attributeset; import android.widget.button; public class fontbutton extends button { public static typeface font_name; public fontbutton(context context) { super(context); if (font_name == null) font_name = typeface.createfromasset(context.getassets(), "fonts/signika-regular.ttf"); this.settypeface(font_name); } public fontbutton(context context, attributeset attrs) { super(context, attrs); if (font_name == null) font_name = typeface.createfromasset(context.getassets(), "fonts/signika-regular.ttf"); this.settypeface(font_name); } public fontbutton(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); if (font_name == null) font_name = typeface.createfromasset(context.getassets(), "fonts/signika-regular.ttf"); this.settypeface(font_name); } } **now in xml file** <com.example.utils.views.fontbutton android:id="@+id/register_user_code" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textsize="17sp" android:background="@drawable/enter_pin" android:onclick="@string/countrycodeclick" android:text="@string/default_country_code" />
Comments
Post a Comment