// Path: LvCursorDemo/app/src/main/java/edu/cs4730/lvcursordemo/db/DatabaseHelper.java
// public class DatabaseHelper extends SupportSQLiteOpenHelper.Callback  {
// 
//     public static final String KEY_ROWID = "_id";
//     public static final String KEY_CODE = "code";
//     public static final String KEY_NAME = "name";
//     public static final String KEY_CONTINENT = "continent";
//     public static final String KEY_REGION = "region";
// 
//     private static final String TAG = "DatabaseHelper";
//     public static final String DATABASE_NAME = "World";
//     public static final String SQLITE_TABLE = "Country";
//     public static final int DATABASE_VERSION = 1;
// 
// 
//     private static final String DATABASE_CREATE =
//         "CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
//             KEY_ROWID + " integer PRIMARY KEY autoincrement," +
//             KEY_CODE + "," +
//             KEY_NAME + "," +
//             KEY_CONTINENT + "," +
//             KEY_REGION + "," +
//             " UNIQUE (" + KEY_CODE +"));";
// 
// 
// 
//     DatabaseHelper() {
//         super(DATABASE_VERSION);
//     }
// 
// 
//     @Override
//     public void onCreate(SupportSQLiteDatabase db) {
//         Log.w(TAG, DATABASE_CREATE);
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
//         Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
//             + newVersion + ", which will destroy all old data");
//         db.execSQL("DROP TABLE IF EXISTS " + SQLITE_TABLE);
//         onCreate(db);
//     }
// }


import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.cursoradapter.widget.CursorAdapter;
import edu.cs4730.lvcursordemo.db.DatabaseHelper;
package edu.cs4730.lvcursordemo;



public class CustomCursorAdapter extends CursorAdapter implements OnClickListener {

    String TAG = "CustomAdapter";
    Context myContext;
    private LayoutInflater inflater;

    public CustomCursorAdapter(Context context, Cursor c) {
        super(context, c, 0);  //0 no content observer on the cursor.  use CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER for

        //needed for the toast later in the code.
        myContext = context;

        //set the inflater for the newView
        inflater = LayoutInflater.from(context);
    }

    /**
     * setup the view from our layout, no data is set here.  Just create the view.
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return inflater.inflate(R.layout.country_custom_info, parent, false);
    }

    /**
     * BindView, is where we set the data fro the view.
     */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // here we are setting our data
        // that means, take the data from the cursor and put it in views
        TextView textViewcode = view.findViewById(R.id.codeC);
        //textViewcode.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
// Path: LvCursorDemo/app/src/main/java/edu/cs4730/lvcursordemo/db/DatabaseHelper.java
// public class DatabaseHelper extends SupportSQLiteOpenHelper.Callback  {
// 
//     public static final String KEY_ROWID = "_id";
//     public static final String KEY_CODE = "code";
//     public static final String KEY_NAME = "name";
//     public static final String KEY_CONTINENT = "continent";
//     public static final String KEY_REGION = "region";
// 
//     private static final String TAG = "DatabaseHelper";
//     public static final String DATABASE_NAME = "World";
//     public static final String SQLITE_TABLE = "Country";
//     public static final int DATABASE_VERSION = 1;
// 
// 
//     private static final String DATABASE_CREATE =
//         "CREATE TABLE if not exists " + SQLITE_TABLE + " (" +
//             KEY_ROWID + " integer PRIMARY KEY autoincrement," +
//             KEY_CODE + "," +
//             KEY_NAME + "," +
//             KEY_CONTINENT + "," +
//             KEY_REGION + "," +
//             " UNIQUE (" + KEY_CODE +"));";
// 
// 
// 
//     DatabaseHelper() {
//         super(DATABASE_VERSION);
//     }
// 
// 
//     @Override
//     public void onCreate(SupportSQLiteDatabase db) {
//         Log.w(TAG, DATABASE_CREATE);
//         db.execSQL(DATABASE_CREATE);
//     }
// 
//     @Override
//     public void onUpgrade(SupportSQLiteDatabase db, int oldVersion, int newVersion) {
//         Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
//             + newVersion + ", which will destroy all old data");
//         db.execSQL("DROP TABLE IF EXISTS " + SQLITE_TABLE);
//         onCreate(db);
//     }
// }


// Path: LvCursorDemo/app/src/main/java/edu/cs4730/lvcursordemo/CustomCursorAdapter.java
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.cursoradapter.widget.CursorAdapter;
import edu.cs4730.lvcursordemo.db.DatabaseHelper;

package edu.cs4730.lvcursordemo;



public class CustomCursorAdapter extends CursorAdapter implements OnClickListener {

    String TAG = "CustomAdapter";
    Context myContext;
    private LayoutInflater inflater;

    public CustomCursorAdapter(Context context, Cursor c) {
        super(context, c, 0);  //0 no content observer on the cursor.  use CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER for

        //needed for the toast later in the code.
        myContext = context;

        //set the inflater for the newView
        inflater = LayoutInflater.from(context);
    }

    /**
     * setup the view from our layout, no data is set here.  Just create the view.
     */
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return inflater.inflate(R.layout.country_custom_info, parent, false);
    }

    /**
     * BindView, is where we set the data fro the view.
     */
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // here we are setting our data
        // that means, take the data from the cursor and put it in views
        TextView textViewcode = view.findViewById(R.id.codeC);
        //textViewcode.setText(cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
        textViewcode.setText(cursor.getString(cursor.getColumnIndex(DatabaseHelper.KEY_CODE)));