Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion starter-code/ShoppingListVer2/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions starter-code/ShoppingListVer2/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;

import ly.generalassemb.drewmahrt.shoppinglistver2.setup.DBAssetHelper;

public class MainActivity extends AppCompatActivity {
ListView mListView;
CursorAdapter mAdapt;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -22,5 +28,29 @@ protected void onCreate(Bundle savedInstanceState) {
DBAssetHelper dbSetup = new DBAssetHelper(MainActivity.this);
dbSetup.getReadableDatabase();

SQLHelper helper = new SQLHelper(MainActivity.this);
Cursor cursor = helper.getItemList();
Log.d("TAG", "Cursor count :" + cursor.getCount());

mListView = (ListView)findViewById(R.id.shopping_list_view);

mAdapt = new CursorAdapter(MainActivity.this,cursor,0) {
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return LayoutInflater.from(context).inflate(R.layout.activity_list_item,parent,false);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
String itemName = cursor.getString(cursor.getColumnIndex("ITEM_NAME"));
TextView nameView = (TextView)view.findViewById(R.id.name_text_view);
nameView.setText(itemName);
}
};
mListView.setAdapter(mAdapt);




}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ly.generalassemb.drewmahrt.shoppinglistver2;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.view.LayoutInflater;

/**
* Created by YPsitos on 2/2/16.
*/
public class SQLHelper extends SQLiteOpenHelper {

public static final int DATABASE_VERSION = 7;
public static final String DATABASE_NAME = "SHOPPING_DB";
public static final String TABLE_NAME = "SHOPPING_LIST";
public static final String COLUMN_ID = "_id";
public static final String[] ICON_COLUMNS = {COLUMN_ID,"ITEM_NAME","DESCRIPTION","PRICE","TYPE"};
private static final String CREATE_SHOPPING_LIST_TABLE = "CREATE TABLE " + TABLE_NAME + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + "ITEM_NAME TEXT, " +
"DESCRIPTION TEXT, PRICE INTEGER, TYPE TEXT)";


public SQLHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_SHOPPING_LIST_TABLE);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);
this.onCreate(db);
}

public Cursor getItemList(){

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(TABLE_NAME,
null,
null,
null,
null,
null,
null,
null);


return cursor;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>