Thanks for the reply!  The reason I asked for an example is because I am
just learning java and I'm not clear on what a construct is.  I was hoping I
could visually identify it if the code was posted, but I'm afraid I can't.
So where is the construct?  

  _____  

From: android-beginners@googlegroups.com
[mailto:android-beginn...@googlegroups.com] On Behalf Of ???
Sent: Monday, March 16, 2009 3:56 AM
To: android-beginners@googlegroups.com
Subject: [android-beginners] Re: Style Attributes


Here is sample codes

In main.Xml => for the view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android";
xmlns:app="http://schemas.android.com/apk/res/com.android.demo.customattribu
te"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<com.android.demo.customattribute.MyView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    app:textSet="@string/t1"
    app:textSetClicked="@string/t2"
    android:id="@+id/myButton"/>
</LinearLayout>

Declare your own styles!!!
/values/attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyView">
<attr name = "textSet" format="string"/>
<attr name = "textSetClicked" format="string"/>
    </declare-styleable>
</resources>



In View class

public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
mAttrs = attrs;
setFocusable(true);
init(context, attrs);
}
private void init(Context context,AttributeSet attrs){
               TypedArray a;
       CharSequence s;
a = context.obtainStyledAttributes(attrs, R.styleable.MyView);
s = a.getString(R.styleable.MyView_textSet);

 if(s != null){
setText(s.toString());
}
}







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to