I have a listview where every item is textview and custom view. Here is layout of listview 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 here is a custom view which draws a ruler and handles horizontal scrolling.
I want to pass same motion event to every item's ruler so that when i scroll one from the list others scroll simultaneously.
In adapter i set listener to custom view. Here is getView portion:
@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;
}
In Main Activity i find my list and set adapter to it. Let's say i have 4 items in listview. But only 2 move simultaneously. What is a proper way to pass same motion event to all rulers in list?