tags:

views:

494

answers:

0

Hello,

I'm trying to create a custom view and then using that custom view in my layout.

My custom view is called "NodePickup" and I have two files for that:

  • res/layout/nodepickup.xml
  • src/some.path.to.package/NodePickup.java

nodepickup.xml

<LinearLayout 
android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="48dip"
android:orientation="horizontal" 
android:background="#aa0000"
xmlns:android="http://schemas.android.com/apk/res/android"&gt;

<ImageView 
 android:id="@+id/ImageView01" 
 android:layout_width="48dip" 
 android:layout_height="48dip"
 android:src="@drawable/arrow_up_green"
 android:background="#FFFFFF">
</ImageView>

<LinearLayout 
 android:id="@+id/LinearLayout01"
 android:background="#FFFFFF" 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 android:orientation="vertical"
 xmlns:android="http://schemas.android.com/apk/res/android"&gt;

 <TextView
  android:text="14:46 (15 min), 1 res"
  android:id="@+id/time"
  android:textSize="12dip"
  android:textColor = "#000000"
  android:layout_width="fill_parent"
        android:layout_height="wrap_content">
 </TextView>

 <TextView
  android:text="Karl XII gatan 6"
  android:id="@+id/road"
  android:textSize="12dip"
  android:textColor = "#000000"
  android:layout_width="fill_parent"
        android:layout_height="wrap_content">
 </TextView>

 <TextView
  android:text="Bertil Håkansson"
  android:id="@+id/name"
  android:textSize="12dip"
  android:textColor = "#000000"
  android:layout_width="fill_parent"
        android:layout_height="wrap_content">
 </TextView>

</LinearLayout>
</LinearLayout>

NodePickup.java

package com.codeshogun.android.swipesample.CustomViews;
import com.codeshogun.android.swipesample.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;

public class NodePickup extends LinearLayout
{
    public NodePickup(Context context, AttributeSet attributeSet)
    {
     super(context, attributeSet);

     LayoutInflater inflater = (LayoutInflater)     context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.nodepickup, this);
    }
}

Im trying to add this view/widget to a layout file, main.xml:

<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.codeshogun.android.swipesample.CustomViews"
    android:id="@+id/flipper"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

<LinearLayout
 android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#FF0000"/>

// If I try to add it here, it wont work
    <com.   // <-- will not give me the widget...?


</LinearLayout>

<LinearLayout
 android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:background="#00FF00"/>
</LinearLayout>
</ViewFlipper>

so the question is, what am I doing wrong?

Regards