Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try setOnItemClickListener instead. It will be fired only when you actually "click" on image, not just select it.</p> <pre><code> gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { // Do what you want } }); </code></pre> <p><em>Update:</em></p> <p>If you want an action with delay, instead of onItemClickListener implementation, you have (at least) two choices. One is to run separate Thread with timeout (Thread.sleep()) and after it is done, you can use Handler to update your activity state. Another option is to use AsyncTask, that is technically the same approach, it only wraps Runnable task and Handler in one inner class. The simplest implementation might be like this:</p> <pre><code> ListUpdater listUpdater; @Override public void onItemSelected(AdapterView&lt;?&gt; arg0, View arg1, int position, long arg3) { // We have to run this thread to add delay before updating activity views if (listUpdater != null) { // Cancel previous task listUpdater.cancel(true); } if (listUpdater == null || position != listUpdater.getPosition()) { listUpdater = null; listUpdater = new ListUpdater(position); listUpdater.execute(); } } class ListUpdater extends AsyncTask&lt;String, String, String&gt; { private int position; public int getPosition() { return position; } public ListUpdater(int position) { this.position = position; } @Override protected String doInBackground(String... params) { try { Thread.sleep(600); // set delay time here } catch (InterruptedException e) { } return null; } @Override protected void onPostExecute(String result) { if (!isCancelled()) { // If another thread is not running, // that is if another item was not selected, // update the activity // Add code here to update the activity // This method works in UI Thread, so you don't need to use Handler // For example: Toast.makeText(YourActivity.this, "" + position, Toast.LENGTH_SHORT).show(); } super.onPostExecute(result); } } </code></pre> <p>This is an example of implementation the delay. It is not necessary precise with your needs, but you can have some ideas from it how to make it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

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

Reload