Ok using a ToggleButton with a custom drawable state background that
has an "android:state_checked" item works for me, thanks.

On Jan 4, 1:02 pm, snctln <[email protected]> wrote:
> Thank you for the prompt reply, I should have read the documentation
> more carefully.
>
> It's too bad though, I would really like to have a button that I can
> set the state of, can I do this programmatically with a regular
> button?  basically be able to set the state to "pressed" or "not-
> pressed", and when the user clicks it it is toggled.  I know the
> ToggleButton class offers similar functionality but I am not sure if
> it will fit exactly what I need due to the green line that identifies
> if it is "on" or "off", maybe a custom background will work for me in
> that case... or maybe I will just have to manually toggle to
> background drawable depending on the state.
>
> On Jan 4, 12:49 pm, Romain Guy <[email protected]> wrote:
>
>
>
>
>
>
>
> > CompoundButton is an abstract class and cannot be used directly since it
> > cannot be instanciated.
> > On Jan 4, 2011 9:46 AM, "snctln" <[email protected]> wrote:
>
> > > I am trying to use a CompoundButton in a project I am working on.
> > > Every time I try and use it by declaring it in my layout xml file I
> > > receive the error "01-04 12:27:46.471: ERROR/AndroidRuntime(1771):
> > > Caused by: android.view.InflateException: Binary XML file line #605:
> > > Error inflating class android.widget.CompoundButton"
>
> > > After fighting the error for a half an hour I decided to try a
> > > minimalistic example. I am using the latest eclipse developer tools,
> > > and targeting android 2.2 makign the minimum sdk required 2.2 (8).
>
> > > Here is the activity java code:
> > > package com.example.CompoundButtonExample;
>
> > > import android.app.Activity;
> > > import android.os.Bundle;
>
> > > public class CompoundButtonExampleActivity extends Activity {
> > > /** Called when the activity is first created. */
> > > @Override
> > > public void onCreate(Bundle savedInstanceState) {
> > > super.onCreate(savedInstanceState);
> > > setContentView(R.layout.main);
> > > }
> > > }
>
> > > Here is the layout xml code:
> > > <?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"
>
> > > <TextView
> > > android:layout_width="fill_parent"
> > > android:layout_height="wrap_content"
> > > android:text="@string/hello"
> > > />
> > > <CompoundButton
> > > android:layout_width="fill_parent"
> > > android:layout_height="wrap_content"
> > > android:text="@string/hello"
> > > />
> > > </LinearLayout>
>
> > > Here is the manifest xml code:
> > > <?xml version="1.0" encoding="utf-8"?>
> > > <manifest xmlns:android="http://schemas.android.com/apk/res/android";
> > > package="com.example.CompoundButtonExample"
> > > android:versionCode="1"
> > > android:versionName="1.0">
> > > <application android:icon="@drawable/icon" android:label="@string/
> > > app_name">
> > > <activity android:name=".CompoundButtonExampleActivity"
> > > android:label="@string/app_name">
> > > <intent-filter>
> > > <action android:name="android.intent.action.MAIN" />
> > > <category
> > > android:name="android.intent.category.LAUNCHER" />
> > > </intent-filter>
> > > </activity>
>
> > > </application>
> > > <uses-sdk android:minSdkVersion="8" />
>
> > > </manifest>
>
> > > As you can see it is just the default hello world project that eclipse
> > > create for you when you start a new Android project. It only differs
> > > in the fact that I add a "CompoundButton" to the main layout in a
> > > vertical LinearLayout.
>
> > > Can anyone confirm this bug? or tell me what I am doing wrong?
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]<android-developers%2Bunsubs
> > >  [email protected]>
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to