开发者

custom view becomes invisible in xml layout

I'm creating custom view derived from EditText. My view is declared as inner class like this:

package com.woodshy.glucoXpert.DPass;

//...

public class DPassValuesEditActivity extends GenericScreenActivity {

//...

public static class DPassValuesEditField extends EditText {
    protected String mDbFieldName;


    public DPassValuesEditField(Context context) {
        super(context);
    }

    public DPassValuesEditField(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.DPassValuesEditField);

        CharSequence s = a
                .getString(R.styleable.DPassValuesEditField_dbFieldName);
        if (s != null) {
            mDbFieldName = s.toString();
        }

    }

    //...
}
}

res/attrs.xml file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="DPassValuesEditField">
        <attr name="dbFieldName" format="string" />
    </declare-styleable>
</resources>

I'm adding my custom view to xml layout:

<?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.woodshy.glucoXpert"
    android:id="@+id/LinearLayout01" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:orientation="vertical">
    <ScrollView android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_gravity="center_vertical"
        android:scrollbars="vertical">
        <RelativeLayout android:id="@+id/editFielsdLayout"
            android:layout_height="fill_parent" android:layout_width="fill_parent"
            android:clickable="true">
            <view
                class="com.woodshy.glucoXpert.DPass.DPassValuesEditActivity$DPassValuesEditField"
                android:id="@+id/edtWeight" android:l开发者_JAVA百科ayout_width="wrap_content"
                android:layout_height="wrap_content" android:width="75px"
                android:maxLines="1" android:layout_below="@+id/TextView01"
                android:lines="1" android:gravity="center" android:imeOptions="flagNoExtractUi"
                android:inputType="numberDecimal" android:maxLength="3"
                app:dbFieldName="Weight"></view>

        </RelativeLayout>


    </ScrollView>
</LinearLayout>

but I cant see it in visual editor (Eclipse SDK, Version: 3.6.1) while it appears in application in run-time and works fine.

Am I doing something wrong? How could I get my custom view visible in visual editor?

thanks.


Had the same problem. Looks like it (plugin) need to reload something before being able to display custom views. Try switch target platform in Graphical Layout Editor from current to some other (for example, from 2.1 to 2.3). That helps and even after switching back to "current" (2.1 in example) it continues to display custom views.

Also sometimes it required to restart eclipse...


How could I get my custom view visible in visual editor?

You can't.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜