There is a listview, where each item consists of TextView and CustomView. XML of each item:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <net.manualuser.calibr.TimeScale android:id="@+id/my_scale" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingLeft="20dp" android:paddingTop="40dp"> <TextView android:id="@+id/counter" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> TimeScale (CustomView) - a scale that scrolls horizontally.
It is necessary that when scrolling any scale from the list, the others scroll simultaneously with it. If I understand correctly, you need to transfer the motion event to the TimeScale of each item in the list.
Adapter code snippet:
@Override public View getView(int i, View view, ViewGroup viewGroup) { View v = view; if(view == null) { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.time_scale_item, viewGroup, false); } scale = (TimeScale)v.findViewById(R.id.my_scale); scale.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { scale.onTouchEvent(event); return false; } }); TextView text = (TextView)v.findViewById(R.id.counter); text.setText(Cities.get(i)); return v; } When I start, I get this: in the list of two items when scrolling the scale from the first item, the second one scrolls with it, but not vice versa (as if the ontouchlistener was not installed on the second scale). In the list of three: the first one scrolls the second one, the second one - the third one, the third one only itself. Those. with any number of items in the list, only two scales scroll simultaneously.
I ask hints that I do wrong.
scale.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { scale.onTouchEvent(event); return false; } });It turns out that you listen to OnTouch on a view and on on the same view you call onTouchEvent. Is it exactly right? - lllyctscalethis field adapter. When you create each individual view, a link to the TimeScale of that most recent view is written there. When scrolling the first element, the second is recorded in the scale (if you have only 2 of them), and everything works. And when the second is scrolled, it is also recorded in scale. - lllyct