1

I tried to combine image and text inside layout. I create layout inside scrollview which, scrollview itself inside ListView. It appear text can be scrolled (because have long text) and problem solved. But new problem appear when i try to click on item in listview. Looks like it cannot be clicked. because when i remove scrollview that wrap text, it can call listener event for item inside it.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"   
android:background="@color/hijau_tua"    
 >

<ImageView 
        android:id="@+id/flag"
        android:layout_width="125dp"
        android:layout_height="80dp"
        android:layout_gravity="top"
        />

<ScrollView
    android:layout_width="match_parent"
        android:layout_height="match_parent"
    >
    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"            
        >    

        <TextView 
            android:id="@+id/txt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textSize="15dp"             
        />          

        <TextView 
            android:id="@+id/cur"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            android:textSize="12dp"        
        />

    </LinearLayout>
    </ScrollView>

That's the layout to display image and textview. I wrap it (TextView) inside ScrollView. (and still, i click one of items, no respond.)

Please point me for the problem. Thank you

Luthfan M
  • 89
  • 2
  • 13
  • you mean the above layout is row in listview? – KOTIOS Jul 06 '14 at 06:14
  • maybe this help : http://stackoverflow.com/questions/6210895/listview-inside-scrollview-is-not-scrolling-on-android/14577399#14577399 – Arash GM Jul 06 '14 at 06:15
  • ^ That's work. But it only work when i touch image. but not work when i touch LinearLayout that wrapped inside scrollview – Luthfan M Jul 06 '14 at 06:21

2 Answers2

0

i had same problem. there are many fixes for ListView within ScrollView. the problem is that they DO NOT perform click on children. The only solution that worked for me was replacing the ScrollView by:

public class VerticalScrollview extends ScrollView {

public VerticalScrollview(Context context) {
    super(context);
}

 public VerticalScrollview(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public VerticalScrollview(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    switch (action)
    {
        case MotionEvent.ACTION_DOWN:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: DOWN super false" );
                super.onTouchEvent(ev);
                break;

        case MotionEvent.ACTION_MOVE:
                return false; // redirect MotionEvents to ourself

        case MotionEvent.ACTION_CANCEL:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: CANCEL super false" );
                super.onTouchEvent(ev);
                break;

        case MotionEvent.ACTION_UP:
                Log.i("VerticalScrollview", "onInterceptTouchEvent: UP super false" );
                return false;

        default: Log.i("VerticalScrollview", "onInterceptTouchEvent: " + action ); break;
    }

    return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    super.onTouchEvent(ev);
    Log.i("VerticalScrollview", "onTouchEvent. action: " + ev.getAction() );
     return true;
}

}

pellyadolfo
  • 981
  • 10
  • 23
-1

example of Scrollview inside listview item is given in below link so perfer this link. it will help u how to implement scrollview scroll insdie listview

this is link:

Scroll view is not working in list view

Community
  • 1
  • 1
shailesh Rohit
  • 407
  • 5
  • 6