When I click the "Show Back" button the second time, the cursor object has been reset. Does anyone have an idea what is going on?

package com.android.flashcardloop;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import static com.android.flashcardloop.Constants.Cardfront;
import static com.android.flashcardloop.Constants.CardBack;
import static com.android.flashcardloop.Constants.SetID;
import static com.android.flashcardloop.Constants.TABLE_NAME2;
import static android.provider.BaseColumns._ID;

/**
 *
 */

public class CardFront extends Activity implements OnClickListener {

    /* (non-Javadoc)
     * @see android.view.View.OnClickListener#onClick(android.view.View)
     */

    private FlashCardDB cards;
    private String[] From = {Cardfront, CardBack};
    private String Where = SetID + " = ?";
    private int setId;
    private Cursor cursor;
    private static int CREATE = 0;
    @Override
    public void onCreate(Bundle savedInstanceState){

        super.onCreate(savedInstanceState);
        setContentView(R.layout.cardfont);
        cards = new FlashCardDB(this);
        Bundle extras = getIntent().getExtras();
        setId = extras.getInt(_ID);

        try{
            cursor = getCards();
            //adapter = new SimpleCursorAdapter(this, R.layout.cardfont,
            //                        cursor, From, To);
            cursor.moveToFirst();
EditText quest = (EditText) findViewById(R.id.cardfrontquestion); String tmp = cursor.getString(cursor.getColumnIndexOrThrow(Cardfront));
            if(tmp != null){
                quest.setText(tmp);
            }
            Button btnAnswer = (Button) findViewById(R.id.showBack);
            Button btnStop = (Button) findViewById(R.id.stop);

            btnAnswer.setOnClickListener(this);
            btnStop.setOnClickListener(this);

        }
        finally{
            //cards.close();
        }
    }
    public void onClick(View v) {
        switch(v.getId()){
        case R.id.showBack:
            showBack();
            break;
        case R.id.stop:
            finish();
            break;
        }

    }

    private Cursor getCards()
    {
        SQLiteDatabase db = cards.getReadableDatabase();
        String[] strSet = {Integer.toString(setId)};
Cursor cursor = db.query(TABLE_NAME2, From, Where, strSet, null, null, null); //Cursor cursor = db.query(TABLE_NAME2, From, null, null, null, null, null);
        startManagingCursor(cursor);
        return cursor;
    }

    private void showBack()
    {
        Intent i = new Intent(this, CardBack.class);
        int col = cursor.getColumnIndexOrThrow(CardBack);
        String tmp = cursor.getString(col);
        i.putExtra(CardBack, tmp);
        startActivityForResult(i, CREATE);
        //cursor = getCards();
    }

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent)
    {
        super.onActivityResult(requestCode, resultCode, intent);

        if(!cursor.moveToNext()){
            finish();
            return;
        }

        if(cursor.isAfterLast()){
            finish();
            return;
        }
        EditText quest = (EditText) findViewById(R.id.cardfrontquestion);
String tmp = cursor.getString(cursor.getColumnIndexOrThrow(Cardfront));
        if(tmp != null){
            quest.setText(tmp);
        }
    }

}

--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to