I'm trying to build a widget that is composed of a few controls grouped together. Here's the widget:
public class VarioView extends RelativeLayout {
private int value;
private ImageView m_circle;
private TextView m_varioText;
private TextView m_units;
public VarioView(Context context)
{
this(context,null);
}
public VarioView(Context context, AttributeSet attr)
{
this(context,attr, 0);
}
public VarioView(Context context, AttributeSet attr, int defStyle)
{
super(context, attr, defStyle);
//View.inflate(context, R.layout.vario, this);
LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
li.inflate(R.layout.vario, this, true);
m_circle = (ImageView)this.findViewById(R.id.VarioCircle);
m_varioText = (TextView)this.findViewById(R.id.VarioText);
//m_circle.setColorFilter(Color.BLUE);
}
public int getValue() {
return value;
}
public void setValue(int value) {
m_varioText.setText(Integer.valueOf(value).toString());
this.value = value;
}
}
Here's the widget xml
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/VarioCircle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:contentDescription="Vario Circle"
android:src="@drawable/circle3" />
<TextView
android:id="@+id/VarioText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="200"
android:textColor="#FF0000"
android:textSize="60sp"
android:textStyle="bold"
android:typeface="monospace" />
<TextView
android:id="@+id/VarioUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/VarioText"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:text="fpm"
android:textSize="20sp" />
</RelativeLayout>
</merge>
Here's circle shape:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false"
android:color="#FF0000" >
<size
android:height="200dip"
android:width="200dip" />
<stroke
android:width="10dp"
android:color="#FF0000" />
</shape>
And in my main view I'm just using it like this:
<com.proflite.VarioView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
My problem is that it works fine when I run it in emulator (or real device), but when I try to go to graphical editor in Eclipse it draws a grey box over the control and gives me this:
The following classes could not be instantiated:
- com.proflite.VarioView (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse
android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F030001.
at android.content.res.BridgeResources.throwException(BridgeResources.java:693)
at android.content.res.BridgeResources.getLayout(BridgeResources.java:271)
at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
at com.proflite.VarioView.<init>(VarioView.java:30)
at com.proflite.VarioView.<init>(VarioView.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0( at sun.reflect.NativeConstructorAccessorImpl.newInstance( at sun.reflect.DelegatingConstructorAccessorImpl.newInstance( at java.lang.reflect.Constructor.newInstance( at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:413)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:170)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:135)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:746)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:718)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:372)
Extra info, I check 0x7F030001
is mapped to R.layout.vario
and the error is coming out of this line: li.inflate(R.layout.vario, this, true);
. Additionally if I change it to li.inflate(R.layout.vario, this);
it doesn't give the error, but the control just shows "blank", doesn't render in editmode (still works when actually run).
I would REALLY like to be able to visualize the layout in the editor cuz it takes a long time to make minor layout alterations and rerun them in emulator.
Thanks
** Note ** the error comes from the layout where the control is placed. It actually renders successfully if I do graphical edit on the control itself.
Well, I feel pretty stupid. Everything worked after I restarted Eclipse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With