Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I hope i understand your question. if so, here's an idea:</p> <p>you need to store a private instance variable that tracks the current position of the image that is being displayed from the coverflow. then, you update it from the <code>setOnItemSelectedListener()</code> method, which is inherited from Gallery. On the "back" or "forward" button, you simply set your current selection +/- 1 depending on the button pressed.</p> <p>so in your Activity, add an instance variable int that will keep track of position like...</p> <pre><code>public class MyActivity { private int currentImagePosition = -1; //add the rest of your onCreate code here... } </code></pre> <p>Next, you need to be able to update the current position of the image that is currently being displayed in the coverflow. you can do so by overriding <code>setOnItemSelectedListener</code> like so (inside your onCreate method):</p> <pre><code>coverFlow.setOnItemSelectedListener(new OnItemSelectedListener(){ @Override public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) { currentImagePosition = position; //this will update your current marker } }; </code></pre> <p>Lastly, all you have to do is set each button's onclick listeners to change to the previous or next image by using <code>setSelection( currentImagePosition+1 )</code> or <code>setSelection( currentImagePosition-1 )</code>. By the way, what's the true or false parameter of <code>setSelection()</code> do? i'm not sure what it does so i'm just going to use <code>true</code> like you did initially. your <code>onCreate()</code> method will now look something like:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState){ //insert your other code in onCreate here in this spot.... //add the following lines to your code: Button goLeft = (Button) findViewById(R.id.button1); goLeft.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { //go to previous image if( currentImagePosition &gt; 0 ){ //i'm assuming you dont want to go left anymore once at the leftmost image coverFlow.setSelection(currentImagePosition - 1, true); } } } ) ; Button goRight = (Button) findViewById(R.id.button2); goRight.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { //go to previous image if( currentImagePosition &lt; coverFlow.getCount()-1 ){ //i'm assuming you dont want to go left anymore once at the leftmost image coverFlow.setSelection(currentImagePosition + 1, true); } } } ) ; } </code></pre> <p>NOTE: the part about updating position is assumed to work from reading <a href="https://stackoverflow.com/questions/5994181/get-the-position-of-the-current-image-displayed-in-gallery"> Get the position of the current image displayed in Gallery</a> so i hope this works. if not, at least i tried :D</p> <p>Good luck!!!</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. 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.
    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