Monday, May 7, 2012

Re: [android-developers] Re: Allow button inside listview to be clickable

The click event is occurring as I tested with a toast message.

The problem seems to be with Background Resource.

Here is the code that I use to create the button:

Button button = new Button(this.mContext);
            button.setId(10000+columnIndex);
            button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
            button.setGravity(Gravity.CENTER);
            button.setText(item);
            button.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));           
            button.setBackgroundDrawable(this.mButtonBackground);
            button.setTextColor(Color.WHITE);
            button.setClickable(true);
            button.setFocusable(true);
            button.setOnClickListener(new OnClickListener() {
               
                public void onClick(View arg0) {
                    Toast toast = Toast.makeText(arg0.getContext(), "Clicked", 5);
                    toast.show();
                   
                }
            });
            container.addView(button);

Here is how I get the drawable:
this.mButtonBackground = this.mResources.getDrawable(R.drawable.schedule_button);


And here is the code from schedule_button.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/gray" />
            <stroke android:width="1dp" android:color="@color/black"/>
        </shape>
    </item>
    <item android:state_focused="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/gray" />
            <stroke android:width="1dp" android:color="@color/black"/>
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#00000000" />
            <stroke android:width="1dp" android:color="#00000000"/>
        </shape>
    </item>

</selector>


How can I give any visual feedback to the button's click event?


Thanks.



On Monday, May 7, 2012 1:30:31 PM UTC-3, MagouyaWare wrote:
The problem is, the button is not clickable and doesn't change its state (at least visually as configured on Background Resource).
  • Try setting the android:focusable and android:focusableInTouchMode attributes to false. 
  • Also, have you verified the button is not clickable?  Put a simple click listener on the button that displays a toast message to be sure... It may just be a problem with your background resource. 
  • Lastly, it may be a problem with having a horizontal scrolling widget inside a vertically scrolling widget but again, I'm not sure about that.  The horizontal scrollview may be stealing the touch events from the buttons...

Thanks,
Justin Anderson
MagouyaWare Developer
http://sites.google.com/site/magouyaware


On Mon, May 7, 2012 at 10:13 AM, Raffaele Sgarro <raffaelesgarro@gmail.com> wrote:
If I understand correctly, you should simply add android:clickable="true" to your list item

On Monday, May 7, 2012 3:43:31 PM UTC+2, Juliano Nunes wrote:
Hi,

I needed to create kind of a sub-list that allows horizontal scrolling, so I created the following structure inside my ListViewItem template:

<HorizontalScrollView android:id="@+id/schedule_scrollView" ... >
        <LinearLayout android:id="@+id/schedule_minutes" ... >
               


                    </LinearLayout>
    </HorizontalScrollView>

And I added dynamically several buttons to this LinearLayout (schedule_minutes), which uses a Background Resource to indicate the button state. The problem is, the button is not clickable and doesn't change its state (at least visually as configured on Background Resource).

How can I fix this?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate