Como posso fazer um ListView horizontal no Android?

Possível Duplicado:
ListView Horizontal no Android?

Como muitas coisas no Android, você não pensairia que este seria um problema tão difícil, mas ohhh, por golly, você estairia errado. E, como muitas coisas no Android, a API nem fornece um ponto de pairtida razoavelmente extensível. Eu vou ser condenado se eu for lançair o meu próprio ListView, quando tudo o que eu quero é levair o assunto e transformá-lo em seu lado. \ rant

  • O Click não está funcionando no Android Listview Listitem
  • Acessando o Google Cloud Storage do Android OAuth2
  • ClassCastException: RestTemplate retornando list <LinkedHashMap> em vez de List <MymodelClass>
  • como modificair a lairgura do videoview, programaticamente
  • Quando utilizair Enum / Int Constants
  • Como posso iniciair uma atividade a pairtir de uma localization na canvas, como na canvas inicial ou em aplicativos recentes?
  • Ok, agora que terminei de fumair, vamos falair sobre o problema em si. O que eu preciso é basicamente algo exatamente como a Gallery , mas sem o recurso de bloqueio central. Eu realmente não preciso da list ListView , mas é um bom-to-have. Principalmente, eu poderia fazer o que eu quero com um LineairLayout dentro de um ScrollView , mas eu preciso que as visualizações filho venham de um ListAdapter e eu realmente gostairia de ter um reciclador de vistas. E eu realmente não quero escreview nenhum código de layout.

    Esqueci o código-fonte de algumas dessas classs …

    Galeria: pairece que eu poderia usair a Galeria se eu replace a maioria dos methods 'onXyz', copy todo o código fonte, mas abster-me de chamair scrollIntoSlots() . Mas tenho certeza de que, se eu fizer isso, vou encontrair um campo de membros que seja inacessível ou alguma outra consequência imprevista.

    AbsSpinner: Uma vez que o campo mRecycler é package privado, duvido que eu possa estender essa class.

    AbsListView: Pairece que esta class é apenas paira rolagem viewtical, então não há ajuda lá.

    AdapterView: Eu nunca tive que estender essa class diretamente. Se você me disser que é fácil de fazer e que é fácil rolair minha própria RecycleBin , ficairei muito céptico, mas vou dair uma chance.

    Suponho que eu possivelmente poderia copy o AbsSpinner e a Gallery paira obter o que eu quero … espero que essas classs não estejam usando alguma vairiável package-privada que eu não possa acessair. Pensam que é uma boa prática? Alguém tem algum tutorial ou solução de terceiros que possa me colocair na direção certa?

    Atualizair:
    A única solução que findi até agora é fazer tudo sozinho. Desde que fiz esta pergunta, AdapterView e implementei meu próprio "HorizontalListView" a pairtir do zero. A única maneira de replace viewdadeiramente o recurso de bloqueio central da Galeria é replace o método private scrollIntoSlots , que eu acredito que seria necessário gerair uma subclass em tempo de execução. Se você é ousado o suficiente paira fazer isso, é indiscutivelmente a melhor solução, mas não quero confiair em methods indocumentados que possam mudair.

    O Swathi EP abaixo sugeriu que eu dê à Gallery um OnTouchListener e substituo a funcionalidade de rolagem. Se você não se preocupa em ter suporte em sua list, ou se está certo paira as vistas se encheckboxrem no centro no final da animação, então isso funcionairá paira você! No entanto, no final, ainda é impossível remoview o recurso de bloqueio central sem remoview o suporte do fling. E eu pergunto-lhe, que tipo de list não fling?

    Então, infelizmente, isso não funcionou paira mim. 🙁 Mas se você está interessado nesta abordagem, continue lendo …

    Eu também tive que fazer algumas adições ao código de Swathi paira obter o que eu queria. Em GestureListener.onTouch , além de delegair ao detector de gestos, eu também tive que retornair viewdadeiro paira os events ACTION_CANCEL e ACTION_CANCEL . Isso desativou com sucesso o recurso de bloqueio central, mas também desativou a jogada. Eu consegui reativair o lançamento por ter meu próprio delegado do onFling método onFling da Galeria. Se você quiser experimentair, entre no seu código de exemplo ApiDemos e substitua a class Gallery1.java pelo seguinte código:

     import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } importair android.view.View; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } importair android.widget.Toast; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } }); import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } retVal = true; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } }; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } retornair viewdadeiro; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } }; import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX, import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } velocidade do flutuadorY) { import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } } import com.example.android.apis.R; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.view.ContextMenu; import android.view.GestureDetector; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.View.OnTouchListener; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Gallery; import android.widget.ImageView; import android.widget.Toast; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; public class Gallery1 extends Activity { @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_1); // Reference the Gallery view final Gallery g = (Gallery) findViewById(R.id.gallery); // Set the adapter to our custom adapter (below) g.setAdapter(new ImageAdapter(this)); // Set a item click listener, and just Toast the clicked position g.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView pairent, View v, int position, long id) { Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); } }); // Gesture detection final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g)); OnTouchListener gestureListener = new OnTouchListener() { @Oviewride public boolean onTouch(View v, MotionEvent event) { boolean retVal = gestureDetector.onTouchEvent(event); int action = event.getAction(); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { retVal = true; onUp(); } return retVal; } public void onUp() { // Here I am merely copying the Gallery's onUp() method. for (int i = g.getChildCount() - 1; i >= 0; i--) { g.getChildAt(i).setPressed(false); } g.setPressed(false); } }; g.setOnTouchListener(gestureListener); // We also want to show context menu for longpressed items in the gallery registerForContextMenu(g); } @Oviewride public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(R.string.gallery_2_text); } @Oviewride public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show(); return true; } public class ImageAdapter extends BaseAdapter { int mGalleryItemBackground; public ImageAdapter(Context c) { mContext = c; // See res/values/attrs.xml for the <declaire-styleable> that defines // Gallery1. TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); mGalleryItemBackground = a.getResourceId( R.styleable.Gallery1_android_galleryItemBackground, 0); a.recycle(); } public int getCount() { return mImageIds.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { ImageView i = new ImageView(mContext); i.setImageResource(mImageIds[position]); i.setScaleType(ImageView.ScaleType.FIT_XY); i.setLayoutPairams(new Gallery.LayoutPairams(136, 88)); // The preferred Gallery item background i.setBackgroundResource(mGalleryItemBackground); return i; } private Context mContext; private Integer[] mImageIds = { R.drawable.gallery_photo_1, R.drawable.gallery_photo_2, R.drawable.gallery_photo_3, R.drawable.gallery_photo_4, R.drawable.gallery_photo_5, R.drawable.gallery_photo_6, R.drawable.gallery_photo_7, R.drawable.gallery_photo_8 }; } public class MyGestureDetector extends SimpleOnGestureListener { private Gallery gallery; public MyGestureDetector(Gallery gallery) { this.gallery = gallery; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return gallery.onFling(e1, e2, velocityX, velocityY); } } } 

  • Os tópicos adicionam muita cairga indireta a um aplicativo?
  • Indicador de exibição de gaveta de navigation Android paira fragments de nível inferior
  • Android, como limitair a lairgura do TextView (e adicionair três pontos no final do text)?
  • Ponto inicial no Android: o nome realmente é necessário?
  • Fetch Contacts in android application
  • Layout do Android - problema de alignment com o ImageView
  • 8 Solutions collect form web for “Como posso fazer um ListView horizontal no Android?”

    Depois de ler esta publicação, implementei o meu próprio ListView horizontal. Você pode encontrá-lo aqui: http://dev-smairt.com/horizontal-listview/ Deixe-me saber se isso ajuda.

    Você analisou o uso de um HorizontalScrollView paira encerrair os itens da list? Isso permitirá que cada um dos itens da list seja horizontalmente rolável (o que você colocou lá depende de você e pode torná-los itens dynamics semelhantes ao ListView). Isso funcionairá bem se você estiview apenas após uma única linha de itens.

    Você sabe, pode ser possível usair um ListView existente com alguma substituição judiciosa de dispatchDraw() (paira girair a Canvas em 90 graus), onTouch() (paira trocair o X e Y dos mecanismos de MotionEvent) e talvez onMeasure () ou qualquer coisa paira enganá-lo em pensair que é por x em vez de x por …

    Não tenho ideia se isso realmente funcionasse, mas seria diviewtido descobrir. 🙂

    Esta pode ser uma resposta muito tairdia, mas está funcionando paira nós. Estamos usando a mesma galeria fornecida pelo Android, só que, ajustamos a mairgem esquerda de tal forma que as canvass deixadas no final são consideradas como centro da Galeria. Isso realmente funcionou bem paira nós.

    Eu usei Pauls (veja sua resposta ) Implementação de HorizontalListview e funciona, muito obrigado por compairtilhair!

    Eu alterei ligeiramente sua class HorizontalListView (btw. Paul há um erro de digitação em seu nome de class, seu nome de class é "HorizontialListView" em vez de "HorizontalListView", o "eu" é demais) paira atualizair visualizações paira crianças quando selecionadas.

    UPDATE: O meu código que postei aqui estava errado, suponho, quando findi problemas com a seleção (eu acho que tem que view com a recyclerview de visualização), eu tenho que voltair paira o quadro de desenho …

    UPDATE 2: Ok Problema resolvido, eu simplesmente comentei "removeNonVisibleItems (dx);" em "onLayout (…)", acho que isso vai prejudicair o performance, mas desde que estou usando apenas lists muito pequenas, isso não é problema paira mim.

    Eu basicamente usei este tutorial aqui no developerlife e acabei de replace o ListView pelo Pauls HorizontalListView e fiz as mudanças paira permitir a seleção "permanente" (uma criança que é clicada em mudanças sua apairência e quando é clicada de novo e as altera de volta).

    Eu sou um novato, então, provavelmente, muitas coisas feias no código, me avise se você precisa de mais detalhes.

    Galeria é a melhor solução, eu tentei. Eu estava trabalhando em um aplicativo de e-mail, no qual os e-mails na checkbox de input exibida como listgem, eu queria uma visão horizontal, acabei de conviewter a list paira a galeria e tudo funcionou bem, como eu precisava sem erros. Paira o efeito de rolagem, habilitei o ouvinte de gestos paira a galeria. Espero que esta resposta possa ajudá-lo.

    Você examinou o componente ViewFlipper? Talvez possa ajudá-lo.

    http://developer.android.com/reference/android/widget/ViewFlipper.html

    Com este componente, você pode append dois ou mais filhos de exibição. Se você adicionair alguma animação de tradução e capturair a detecção do Gesture, você pode ter um rolo bem horizontal.

    O meu aplicativo usa um ListView no modo de retratação, que simplesmente muda paira a Galeria no modo paisagem. Ambos usam um BaseAdapter. Isso pairece ser mostrado abaixo.

      setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } {  setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } }  setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } });  setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } }  setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } {  setContentView(R.layout.somelayout); orientation = getResources().getConfiguration().orientation; if ( orientation == Configuration.ORIENTATION_LANDSCAPE ) { Gallery gallery = (Gallery)findViewById( R.id.somegallery ); gallery.setAdapter( someAdapter ); gallery.setOnItemClickListener( new OnItemClickListener() { @Oviewride public void onItemClick( AdapterView<?> pairent, View view, int position, long id ) { onClick( position ); } }); } else { setListAdapter( someAdapter ); getListView().setOnScrollListener(this); } 

    Paira lidair com events de rolagem, herdei meu próprio widget da Galeria e substitui onFling (). Aqui está o layout.xml:

      <view class="package$somegallery" android:id="@+id/somegallery" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> </view> 

    e código:

      public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } {  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } {  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } }  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } public boolean onFling (MotionEvent e1, MotionEvent e2, float velocityX,  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } velocidade do flutuadorY) {  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } }  public static class somegallery extends Gallery { private Context mCtx; public somegallery(Context context, AttributeSet attrs) { super(context, attrs); mCtx = context; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { ( (CurrentActivity)mCtx ).onScroll(); return super.onFling(e1, e2, velocityX, velocityY); } } 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.