title: Next button should get next record
body: <pre><code>package com.ctis.abc_final;
  
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileOutputStream;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  
  import android.app.Activity;
  import android.database.Cursor;
  import android.os.Bundle;
  import android.view.View;
  import android.view.Window;
  import android.widget.ListView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  public class DisplayActivity extends Activity {
  
      DBAdapter db;
  
      TextView t1;
      TextView t2;
      TextView t3;
      TextView t4;
      TextView t5;
      TextView t6;
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          this.requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(R.layout.display);
  
          try {
              String destPath = "/data/data/" + getPackageName()
                      + "/databases/Ctis487";
              File file = new File(destPath);
              if (!file.exists()) {
                  CopyDB(getBaseContext().getAssets().open("Ctis487"),
                          new FileOutputStream(destPath));
              }
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          t1 = (TextView) findViewById(R.id.textView8);
          t2 = (TextView) findViewById(R.id.textView9);
          t3 = (TextView) findViewById(R.id.textView10);
          t4 = (TextView) findViewById(R.id.textView11);
          t5 = (TextView) findViewById(R.id.textView12);
          t6 = (TextView) findViewById(R.id.textView13);
  
          db = new DBAdapter(this);
  
      }
  
      public void CopyDB(InputStream inputStream, OutputStream outputStream)
              throws IOException {
          // Copy 1K bytes at a time
          byte[] buffer = new byte[1024];
          int length;
          while ((length = inputStream.read(buffer)) &gt; 0) {
              outputStream.write(buffer, 0, length);
          }
          inputStream.close();
          outputStream.close();
      }
  
      public void onClick(View v) {
          switch (v.getId()) {
          case R.id.Button01:
              // Get all contacts
              db.open();
              Cursor c = db.getAllContacts();
              if (c.moveToFirst()) {
                  do {
                      DisplayContact(c);
                  } while (c.moveToNext());
              }
              db.close();
  
              break;
          }
  
      }
  
      public void DisplayContact(Cursor c) {
  
          t1.setText("" + c.getString(3));
          t2.setText("" + c.getString(1));
          t3.setText("" + c.getString(2));
          t4.setText("" + c.getString(4));
          t5.setText("" + c.getString(5));
          t6.setText("" + c.getString(6));
  
      }
  }
  </code></pre>
  
  <p>Above code only get the last value. What i want to do is when you click the next button, it should get the next record. How can i do that? i defined on click above code. But it only retrieves last record why?</p>
  
  <p><strong>this only retrieve first record. UPDATE Please look at it.</strong></p>
  
  <pre><code>switch (v.getId()) {
  
          case R.id.Button01:
              int record_position =  -1;
  
              // Get all contacts
              db.open();
              Cursor c = db.getAllContacts();
              if (record_position == -1){
                  if (c.moveToFirst()) {
                      record_position = c.getPosition();
                      DisplayContact(c);
                  }
              }
              else if (c.moveToPosition(record_position)){     
                  c.moveToNext();
                  record_position = c.getPosition();
                  DisplayContact(c);
              }
              else {
                  if(c.moveToFirst()){
                      record_position = c.getPosition();
                      DisplayContact(c);
                  }
              }
              db.close();
              break;
  </code></pre>