title: ViewPager offsets cursor position
body: <p>I have a situation similar to this <a href="https://stackoverflow.com/questions/15483681/viewpager-getting-wrong-cursor-in-simplecursoradapter">ViewPager. Getting wrong cursor in SimpleCursorAdapter</a> and this <a href="https://stackoverflow.com/questions/19233021/viewpager-cursor-positon">ViewPager Cursor positon</a> but the questions had no
  applicable answer. </p>
  
  <p><strong>Situation</strong></p>
  
  <p>I am loading the views in my viewpager from a database (cursor). When I set the text for the items (<code>Buttons</code>, <code>TextViews</code> etc) it does this with the correct cursor (in the expected position).
  But when i try to <code>button.getText()</code> it shows me the text from the next position in the database (same with buttons etc). If the user swipes forward, the cursor returns values in the next position and if the user swipes backward, it returns values in the previous position</p>
  
  <p>So at position <code>x</code> swiping forward returns cursor at position <code>x + 1</code> and swiping backwards returns cursor at postion <code>x - 1</code>. 
  How can i solve this? This is my <code>PagerAdapter.instantiateItem</code></p>
  
  <pre><code>    public Object instantiateItem(View view, int position) {
  
          cursor.moveToPosition(position);
          int cus = cursor.getPosition();
          Log.d(DBHelper.TAG, Integer.toString(cus) + " current cursor position ");
  
          final ViewPager pager = (ViewPager) view.findViewById(R.id.pager_nav);
          ScrollView layout = (ScrollView) inflater.inflate(R.layout.question_activity, null);
  
          if (cursorCategory != null &amp;&amp; cursorCategory.moveToFirst()){
              String s = cursorCategory.getString(cursorCategory.getColumnIndex("name"));
              ((TextView)layout.findViewById(R.id.text_category)).setText(s);
          }
  
          Typeface tpf = Typeface.createFromAsset(context.getAssets(), "Roboto-Light.ttf");
          String text = cursor.getString(cursor.getColumnIndex("question_text"));
          TextView question_text =  (TextView)layout.findViewById(R.id.text_question);
          question_text.setText(text);
          Log.d("question_text", question_text.getText() + " " + position + " " + text);
          question_text.setTypeface(tpf);
  
          final String qPos = Integer.toString(position + 1) + ".";
          TextView question_position = (TextView) layout.findViewById(R.id.text_position);
          question_position.setText(qPos);
          question_position.setTypeface(tpf);
  
          this.rightAnswer = cursor.getString(cursor.getColumnIndex(DBHelper.RIGHT_ANSWER));
          this.wrongAnswer1 = cursor.getString(cursor.getColumnIndex(DBHelper.WRONG_ANSWER1));
          this.wrongAnswer2 = cursor.getString(cursor.getColumnIndex(DBHelper.WRONG_ANSWER2));
  
          optionsArray = new ArrayList&lt;String&gt;();
          optionsArray.clear();
          optionsArray.add(this.rightAnswer);
          optionsArray.add(this.wrongAnswer1);
          optionsArray.add(this.wrongAnswer2);
          Collections.shuffle(optionsArray);
  
          option1 = (Button) layout.findViewById(R.id.button_option1);
          option1.setText((CharSequence) this.optionsArray.get(0));
  
          option2 = (Button) layout.findViewById(R.id.button_option2);
          option2.setText((CharSequence) this.optionsArray.get(1));
  
          option3 = (Button) layout.findViewById(R.id.button_option3);
          option3.setText((CharSequence) this.optionsArray.get(2));
  
          if (this.optionsArray.get(0).equalsIgnoreCase(this.rightAnswer)) {
              this.option1.setTag(DBHelper.RIGHT_ANSWER);
          } else if (!this.rightAnswer.equalsIgnoreCase((String) this.optionsArray.get(0))) {
              this.option1.setTag("wrong");
          }
  
          if (this.rightAnswer.equalsIgnoreCase((String) this.optionsArray.get(1))) {
              this.option2.setTag(DBHelper.RIGHT_ANSWER);
          } else if (!this.rightAnswer.equalsIgnoreCase((String) this.optionsArray.get(1))) {
              this.option2.setTag("wrong");
          }
  
          if (this.rightAnswer.equalsIgnoreCase((String) this.optionsArray.get(2))) {
              this.option3.setTag(DBHelper.RIGHT_ANSWER);
          } else if (!this.rightAnswer.equalsIgnoreCase((String) this.optionsArray.get(2))){
              this.option3.setTag("wrong");
          }
  
          private int getItem(int i) {
              return i += pager.getCurrentItem();
          }
      });
  
      option1.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              String Tag = option1.getTag().toString();
              Toast.makeText(context, Tag + " " + option1.getText(), Toast.LENGTH_SHORT).show();
  
          }
      });
  
      option2.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              String Tag = option2.getTag().toString();
              Toast.makeText(context, Tag + " " + option2.getText(), Toast.LENGTH_SHORT).show();
  
          }
      });
  
      option3.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View arg0) {
              String Tag = option3.getTag().toString();
              Toast.makeText(context, Tag + " " + option3.getText(), Toast.LENGTH_SHORT).show();
  
          }
      });
  }
  </code></pre>
  
  <p>And my onLoadFinished()</p>
  
  <pre><code>    @Override
  public void onLoadFinished(Loader&lt;Cursor&gt; loader, Cursor cursor) {
  
      switch (loader.getId()) {
      case QUESTION_TEXT:
          Log.d(" Selection Position", " Selection Position" + selcectionPosition );
          Log.d(" Activity Position", cursor.getPosition() + " Activity Position");
          mAdapter.swapCursor(cursor);
          mAdapter.notifyDataSetChanged();
          pager.setCurrentItem(selcectionPosition, true);
          break;
      }
  }
  </code></pre>
  
  <p>Hoping to get some help.</p>