The problem your facing is with this bit of code:

                LayoutInflater inflate =
(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                inflate.inflate(R.layout.my_component, null);

You are telling it to inflate, but you are not telling it where, or
that MyComponent should be this bit of code.

That being said, I'm not sure the best way to inflate a view, however
I did do something similar as follows:

snip - prefs_ls.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/
android">
...
        <com.simplified.InfoPreference
            android:key="use_kl"
            android:title="@string/use_kl"
            android:dependency="use_kl"
            android:layout="?android:attr/preferenceLayoutChild"
            android:summaryOn="@string/use_kl_summaryon"
            android:summaryOff="@string/use_kl_summaryoff"
            android:defaultValue="false"
            android:enabled="false" />
...
</PreferenceScreen>

InfoPreference.java:
public class InfoPreference extends CheckBoxPreference
{
    // This is the constructor called by the inflater
    public InfoPreference (Context context, AttributeSet attrs)
    {
        super (context, attrs);
        setWidgetLayoutResource (R.layout.infopreference_widget);
    }
    ...
}

And then I have a infopreference_widget.xml file for that layout.


Hope that helps,
-Kitzy


On Apr 26, 11:45 am, Victor Hugo <vhs...@gmail.com> wrote:
> Hi people,
>
> Im trying create my own component.
>
> I go show my source code for you.
>
> (MyComponent.class)
>
> package com.victor.componets;
>
> import com.victor.R;
> import android.content.Context;
> import android.util.AttributeSet;
> import android.view.LayoutInflater;
> import android.view.View;
>
> public class MyComponent extends View {
>
>         public MyComponent(Context context, AttributeSet attrs) {
>                 super(context, attrs);
>                 LayoutInflater inflate =
> (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
>                 inflate.inflate(R.layout.my_component, null);
>         }
>
> }
>
> (my_component.xml)
>
> <?xml version="1.0" encoding="utf-8"?>
> <TableLayout android:id="@+id/widget32"
>         android:layout_width="fill_parent"
> android:layout_height="fill_parent"
>         android:orientation="vertical" xmlns:android="http://
> schemas.android.com/apk/res/android">
>         <Button android:id="@+id/widget28"
> android:layout_width="wrap_content"
>                 android:layout_height="wrap_content" android:text="Button">
>         </Button>
> </TableLayout>
>
> (main.xml)
>
> <?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.victor.componets.MyComponent
>                 android:id="@+id/widget33" android:layout_width="wrap_content"
>                 android:layout_height="wrap_content" 
> android:orientation="vertical" /
>
>
>
> </LinearLayout>
>
> when I run the application come the main.xml layout but dont appear
> my component com.victor.componets.MyComponent
>
> anyone know what be wrong???
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Beginners" group.
>
> NEW! Try asking and tagging your question on Stack Overflow 
> athttp://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/android-beginners?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

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