title: Android Studio Video Player buttons and list index
body: <p>I am learning Android Studio and java, my level is totaly beginner but I am trying to make video player with simple buttons: <code>Previous</code>, <code>Next</code>, <code>exit</code> and option checkbox for random video from list.</p>
  
  <p>So far it's working but just once, next clicks are just starting same video from beginning. Can someone have mercy and help me? I was looking for some codes for 3 days.</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;
  
  &lt;VideoView
      android:layout_width="320dp"
      android:layout_height="240dp"
      android:id="@+id/videoView"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;Button
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Następny"
      android:id="@+id/next"
      android:layout_below="@+id/videoView"
      android:layout_alignRight="@+id/videoView"
      android:layout_alignEnd="@+id/videoView" /&gt;
  
  &lt;Button
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Poprzedni"
      android:id="@+id/prev"
      android:layout_alignTop="@+id/next"
      android:layout_alignParentLeft="true"
      android:layout_alignParentStart="true" /&gt;
  
  &lt;Button
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Wyjście"
      android:id="@+id/exit"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;CheckBox
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Losowo"
      android:id="@+id/checkBox"
      android:layout_alignTop="@+id/prev"
      android:layout_centerHorizontal="true"
       /&gt;
  
  &lt;Button
      style="?android:attr/buttonStyleSmall"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="Start/Stop"
      android:id="@+id/start"
      android:layout_below="@+id/checkBox"
      android:layout_centerHorizontal="true" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  
  
  <pre><code>package no.norskavis.norw1;
  
  import android.net.Uri;
  import android.support.v7.app.ActionBarActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.CheckBox;
  import android.widget.VideoView;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.ListIterator;
  import java.util.Random;
  
  
  public class MainActivity extends ActionBarActivity {
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
      Button btn1 = (Button) findViewById(R.id.exit);
      btn1.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              finish();
              System.exit(0);
          }
  
      });
          final VideoView videoView = (VideoView) findViewById(R.id.videoView);
          Uri video = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.intro);
          videoView.setVideoURI(video);
          videoView.start();
      final List listA = new ArrayList&lt;&gt;();
  
          listA.add("android.resource://" + getPackageName() + "/" + R.raw.intro);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc1);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc2);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc3);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc4);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc5);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc6);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc7);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc8);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc9);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc10);
      listA.add("android.resource://" + getPackageName() + "/" + R.raw.czesc11);
  
  
  
  
                  CheckBox chck= (CheckBox) findViewById(R.id.checkBox);
  
                  if (chck.isEnabled()) {
  
  
  
                      Button next = (Button) findViewById(R.id.next);
                      next.setOnClickListener(new OnClickListener() {
                          Object randomItem = listA.get(new Random().nextInt(listA.size()));
                          @Override
  
  
                          public void onClick(View v) {
                              Uri video = Uri.parse((String) randomItem);
                              videoView.setVideoURI(video);
                                                      }
                                                                      }
                                              );
                                          }
                  else
  
                  { Button next = (Button) findViewById(R.id.next);
                      next.setOnClickListener(new OnClickListener() {
                                                  public void onClick(View v){
                                                      ListIterator&lt;String&gt; listIterator = listA.listIterator();
                                                      Uri video = Uri.parse(String.valueOf(listIterator.nextIndex()));
                                                      videoView.setVideoURI(video);
                                                                              }
                                                                      }
                                              );
                  }
      }
  </code></pre>