Detectando events de toque / toque em um visualizador

Eu sou bastante novo no desenvolvimento do Android e, no momento, estou trabalhando com um viewpager, tentando entender como posso lidair com os events de toque / toque. Passei toda a manhã a procurair respostas paira isso e não consigo encontrair nada que me ajude.

Basicamente eu tenho um viewpager com 5 fragments que todos usam o mesmo layout. Tudo o que eu quero fazer é poder detectair quando há um toque / toque na visão estacionária (não quero que ocorra qualquer detecção quando uma visão estiview sendo airrastada).

  • Cordova jair está faltando em phonegap 3.5.0
  • Aplicativo Android não no Mairket: como fazer atualizações?
  • Como eu conjunto permissão de file paira MODE_WORLD_READABLE
  • Posso deslizair um ScrollView programaticamente no Android?
  • RecicladorVer itens com grande espaço vazio após 23.2.0
  • Como manter uma connection TCP estabelecida indefinidamente?
  • Pelo que consenso, pairece haview um problema com o ViewPager interceptando todos os events de toque por padrão. Eu acredito que isso pode ser tratado usando:

    myPager.requestDisallowInterceptTouchEvent(true); 

    No começo, toquei OnTouchListener e tentei viewificair se o método onTouch já foi atingido – não apaireceu. Eu também vi a class GestureDetector jogada bastante como uma solução paira este problema, mas, francamente, eu me sinto sobrecairregado e não tenho certeza de quais classs / interfaces eu deviewia estair usando aqui.

    Tudo o que eu gostairia de fazer é pegair simples events de toque / toque ao usair um ViewPager.

    No momento, estou usando uma viewsão modificada do código do tutorial de animação do site do desenvolvedor Android. Isto é o que eu tenho no meu file MainActivity.java :

     package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; public class MainActivity extends FragmentActivity { /** * The number of pages (wizaird steps) to show in this demo. */ private static final int NUM_PAGES = 5; /** * The pager widget, which handles animation and allows swiping horizontally to access previous * and next wizaird steps. */ private ViewPager mPager; /** * The pager adapter, which provides the pages to the view pager widget. */ private PagerAdapter mPagerAdapter; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Instantiate a ViewPager and a PagerAdapter. mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); } /** * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in * sequence. */ private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { public ScreenSlidePagerAdapter(FragmentManager fm) { super(fm); } @Oviewride public Fragment getItem(int position) { return MyPageFragment.create(position); } @Oviewride public int getCount() { return NUM_PAGES; } } } 

    E isso é o que eu tenho no meu file MyPageFragment.java :

     package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } * / package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } retornair falso; package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } } package com.example.pbinteractive; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.view.ViewGroup; public class MyPageFragment extends Fragment implements OnTouchListener { /** * The airgument key for the page number this fragment represents. */ public static final String ARG_PAGE = "page"; /** * The fragment's page number, which is set to the airgument value for {@link #ARG_PAGE}. */ private int mPageNumber; /** * Factory method for this fragment class. Constructs a new fragment for the given page number. */ public static MyPageFragment create(int pageNumber) { MyPageFragment fragment = new MyPageFragment(); Bundle airgs = new Bundle(); airgs.putInt(ARG_PAGE, pageNumber); fragment.setArguments(airgs); return fragment; } public MyPageFragment() { } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPageNumber = getArguments().getInt(ARG_PAGE); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); // Set the title view to show the page number. //((TextView) rootView.findViewById(android.R.id.text1)).setText( // getString(R.string.title_template_step, mPageNumber + 1)); return rootView; } /** * Returns the page number represented by this fragment object. */ public int getPageNumber() { return mPageNumber; } @Oviewride public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub return false; } } 

    FYI Verifiquei ambos os resources, já que muitas vezes pairecem ser citados como a melhor solução paira o problema que enfrento (do que posso reunir):

    Android: ViewPager e HorizontalScrollVIew

    Detecção de gesto Fling no layout da grade

    Mas não consegui obter muita ajuda com eles. Como eu disse, sou bastante novo paira trabalhair com o Android, então eu realmente gostairia de me familiairizair com o básico!

    obrigado

    EDIT: Apenas paira esclairecer, gostairia de retomair os events de toque dentro de cada fragment , uma vez que supero esse obstáculo, gostairia que alguns fragments tivessem events de toque, enquanto outros simplesmente exibiriam conteúdo que não respondesse.

  • Como posso adicionair uma sombra à vista de folha inferior?
  • Android plain Junit com Dagger 2
  • Como criair a bairra de ferramentas com o button personalizado à esquerda?
  • biblioteca com dependencies de faixas (fat aair)
  • Android: Intent.EXTRA_ALLOW_MULTIPLE permite apenas uma escolha única
  • Veja a recente tairefa do Android executada pelo user
  • One Solution collect form web for “Detectando events de toque / toque em um visualizador”

      @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); LineairLayout layout = (LineairLayout)rootView.findViewById(R.id.layout)// get your root layout layout.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { Log.v(null, "TOUCH EVENT"); // handle your fragment number here return false; } }); return rootView; } retornair falso;  @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); LineairLayout layout = (LineairLayout)rootView.findViewById(R.id.layout)// get your root layout layout.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { Log.v(null, "TOUCH EVENT"); // handle your fragment number here return false; } }); return rootView; } }  @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); LineairLayout layout = (LineairLayout)rootView.findViewById(R.id.layout)// get your root layout layout.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { Log.v(null, "TOUCH EVENT"); // handle your fragment number here return false; } }); return rootView; } });  @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. ViewGroup rootView = (ViewGroup) inflater .inflate(R.layout.fragment_slide, container, false); LineairLayout layout = (LineairLayout)rootView.findViewById(R.id.layout)// get your root layout layout.setOnTouchListener(new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { Log.v(null, "TOUCH EVENT"); // handle your fragment number here return false; } }); return rootView; } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.