Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I didn't try it, but this may help you:</p> <p>Override <code>onTouchEvent</code> in your <code>gallary1</code>, then copy the <code>MotionEvent</code> and pass it to the other Gallary lets name it as <code>gallary1</code></p> <pre><code>@Override public boolean onTouchEvent(MotionEvent event) { MotionEvent event2=MotionEvent.obtain(event); gallery2.onTouchEvent(event2); return super.onTouchEvent(event); } </code></pre> <hr> <p>Full Code (its working):</p> <pre><code>public class MyGallary extends Gallery { public MyGallary(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyGallary(Context context, AttributeSet attrs) { super(context, attrs); } public MyGallary(Context context) { super(context); } private MyTouchListener myTouchListener; @Override public boolean onTouchEvent(MotionEvent event) { if (myTouchListener != null) { myTouchListener.onTouch(event); } return super.onTouchEvent(event); } public MyTouchListener getMyTouchListener() { return myTouchListener; } public void setMyTouchListener(MyTouchListener myTouchListener) { this.myTouchListener = myTouchListener; } } </code></pre> <hr> <pre><code>public interface MyTouchListener { public void onTouch(MotionEvent event); } </code></pre> <hr> <pre><code>public class MainActivity extends Activity { MyGallary gallary1; Gallery gallary2; MyTouchListener listener1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gallary1 = (MyGallary) findViewById(R.id.myGallary1); listener1 = new MyTouchListener() { @Override public void onTouch(MotionEvent event) { MotionEvent event2 = MotionEvent.obtain(event); gallary2.onTouchEvent(event2); } }; gallary1.setMyTouchListener(listener1); gallary2 = (Gallary) findViewById(R.id.Gallary2); int[] array = new int[] { R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher, R.drawable.ic_launcher }; ImageAdapter adapter1 = new ImageAdapter(array); gallary1.setAdapter(adapter1); ImageAdapter adapter2=new ImageAdapter(array); gallary2.setAdapter(adapter2); } class ImageAdapter extends BaseAdapter { int[] array; public ImageAdapter(int[] array) { this.array = array; } @Override public int getCount() { return array.length; } @Override public Object getItem(int position) { return array[position]; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { ImageView imageView = new ImageView(MainActivity.this); Gallery.LayoutParams params = new Gallery.LayoutParams( Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT); imageView.setLayoutParams(params); convertView = imageView; } ImageView imageView = (ImageView) convertView; imageView.setImageResource((Integer) getItem(position)); return convertView; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload