Hi, i m new to android. I am trying to create custom component.
developer wil use this component just like any other component like
textview or editText in his layout.xml file. I want this component to
be created and rendered by java file only. No layout xml is used. i am
not sure whether to extend my class to View or ViewGroup or some
layout and then add say textview and/or edittext. i tried by extending
to View class but faced many problems in adding simple textVIew to it.

I am pasting following code. Problem with it is. I can see red square
(which i think is a viewgroup) on emulator but not able to see
textView added to it. Please help me. i have expressed my intentions
above, to create forms or a form like reusable component.

//My form impletation java file
public class Form extends ViewGroup
{
        AttributeSet attrSet;
        LinearLayout.LayoutParams layParams;
        Context moContext;
        public Form(Context context)
        {
                super(context);
                this.moContext = context;
                initForm();
        }

        public Form(Context context, AttributeSet attributeSet)
        {
                super(context,attributeSet);
                this.attrSet = attributeSet;
                this.moContext = context;
                initForm();
        }

        @Override
        protected void onDraw(Canvas canvas)
        {
                super.onDraw(canvas);
                setVisibility(VISIBLE);
                initForm();
        }

        public void initForm()
        {
                setVisibility(VISIBLE);
                layParams = new 
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT);
                layParams.gravity = LinearLayout.HORIZONTAL;
                layParams.setMargins(5, 5, 5, 5);
                setLayoutParams(layParams);
                setBackgroundColor(Color.RED);
                TextView textView = new TextView(getContext(), attrSet);
                textView.setText("AAAAAAAAAAAAA");
                textView.setBackgroundColor(Color.YELLOW);
                textView.bringToFront();
                invalidate();
        }
        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b)
        {

        }

}

//layout.xml which will be used by some activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

 <com.android.custom.Form
 android:id="@+id/mform"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
    />

</LinearLayout>


Please guide me through.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to