开发者

Can't use/find my custom view when defining layout

开发者 https://www.devze.com 2022-12-14 16:47 出处:网络
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:

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/com.codeshogun.android.swipesample/NodePickup.java

nodepickup.xml:

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

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

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

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

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

        <TextView
            android:id="@+id/name"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Bertil Håkansson"
            android:textColor="#000000"
            android:textSize="开发者_如何学C12dip" >
        </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);
    }
}

I am 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>

What am I doing wrong?

0

精彩评论

暂无评论...
验证码 换一张
取 消