Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Horizontal Scrollview inside ListView item?

I have a ListView item layout that is using a HorizontalScrollView in the center. I have used the android attribute "android:descendantFocusability="blocksDescendants"" on my parent LinearLayout so that the ListView items are still selectable.

The problem I am having is that when clicking the part of the ListView item which is the HorizontalScrollView, the ListView item click event is not called.

How can I get the click event of the HorizontalScrollView to call the ListView list item click event?

like image 319
startupsmith Avatar asked Jun 30 '12 09:06

startupsmith


1 Answers

HorizontalScrollView doesn't have "onClick()", see this http://developer.android.com/reference/android/widget/HorizontalScrollView.html

It support gestures and have "onTouchEvent(MotionEvent ev)"

So you can use it as click. See followin demo which I hav prepared.

//      Followin  code will not work  for HorizontalScrollView
        /*hsv1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(HorizontalListActivity.this, tvMiddle.getText().toString().trim(), Toast.LENGTH_SHORT).show();
            }
        });*/

        hsv1.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(YourActivity.this, "Your Msg", Toast.LENGTH_SHORT).show();
                return false;
            }
        });
like image 162
Chintan Raghwani Avatar answered Oct 03 '22 19:10

Chintan Raghwani