0

I've searched around and has read this thread and this thread and so, but nothing helped me .

I have a listview that contains custom layouts. the layout has a custom seekbar. I've used the seekbar out of the listview and it works very well but when uses in list view the onTouch event does not called correctly and runs only when I'm start touching it.

this is a part of my code in getView:

          newSimpleDim.layTouch1.setOnTouchListener(new OnTouchListener() {

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    int x = (int) event.getX();
                    int y = (int) event.getY();
                    if (y < 0)
                        y = 0;
                    if (y > dimHeight)
                        y = dimHeight;

                    G.log("Event : " + event.getAction());

                    switch (event.getAction()) {
                        case MotionEvent.ACTION_MOVE:
                            setHeight(newSimpleDim.layGray1, y);
                            setHeight(newSimpleDim.layGreen1, dimHeight - y);
                            setPadding(newSimpleDim.imgGreen1, -y);
                            newSimpleDim.txtlbl1.setText("" + (100 - ((int) ((y / (double) dimHeight) * 100))));
                            break;
                    }
                    return true;
                }
            });

and this is list item layout :

<LinearLayout
        android:id="@+id/dimmerOne"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/layTouch1"
            android:layout_width="wrap_content"
            android:layout_height="202dp"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/layGray1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dip"
                android:layout_marginRight="20dp"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/imgGray1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="matrix"
                    android:src="@drawable/lay_component_dimmer_slider_off" />
            </LinearLayout>

            <LinearLayout
                android:id="@+id/layGreen1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/imgGreen1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scaleType="matrix"
                    android:src="@drawable/lay_component_dimmer_slider_on" />
            </LinearLayout>
        </LinearLayout>

        <TextView
            android:id="@+id/txtlbl1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="TextView"
            android:typeface="monospace" />

    </LinearLayout>
Community
  • 1
  • 1
Ahmad Behzadi
  • 1,006
  • 15
  • 30

1 Answers1

0

This problem seems similar to the one I was facing, I am has checkbox and on itemClickListener was not working, did the following to make itemClickListener work,

Added the following properties to the checkbox,

android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"

and ItemClickListner started working.

for you if onTouch is not getting invoked for the seek bar then add the above code to the layout.

For detailed example for checkbox clickable in listview you can go through the link, and you can apply the same concept to make your onTouch wor

http://knowledge-cess.com/android-itemclicklistner-with-checkbox-or-radiobutton/

Hope it helps Cheers!!

Gokul Kulkarni
  • 2,069
  • 3
  • 26
  • 42