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.

2 changes: 1 addition & 1 deletion 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
@@ -0,0 +1,57 @@
package ly.generalassemb.drewmahrt.shoppinglistver2;

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

/**
* Created by faraz on 2/2/16.
*/
public class DatabaseHelper extends SQLiteOpenHelper {

public static final String TABLE_NAME = "SHOPPING_LIST";
public static final String ID = "_id";
public static final String ITEM_NAME = "ITEM_NAME";
public static final String DESCRIPTION = "DESCRIPTION";
public static final String PRICE = "PRICE";
public static final String TYPE = "TYPE";
public static final String TEXT = "TEXT";

public DatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {
final String CREATE_TABLE = "CREATE TABLE " +
TABLE_NAME +
" (" + ID + " INTEGER PRIMARY KEY, " +
ITEM_NAME + " " +
TEXT + ", " +
DESCRIPTION + " " +
TEXT + ", " +
PRICE + " " +
TEXT + ", " +
TYPE + " " +
TEXT + ")";

db.execSQL(CREATE_TABLE);
}

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

public void insert(int id, String itemName, String description, String price, String type) {
SQLiteDatabase db = getReadableDatabase();
db.execSQL("INSERT INTO " + TABLE_NAME + " VALUES ('" + id + "', '" + itemName + "', '" + description + "', '" + price + "', '" + type + "')");
}

public Cursor getValues() {
SQLiteDatabase db = getReadableDatabase();
return db.query(TABLE_NAME, null, null, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ly.generalassemb.drewmahrt.shoppinglistver2;

import android.content.Context;
import android.app.SearchManager;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

Expand All @@ -18,9 +17,31 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

//Ignore the two lines below, they are for setup
DBAssetHelper dbSetup = new DBAssetHelper(MainActivity.this);
dbSetup.getReadableDatabase();

DatabaseHelper helper = new DatabaseHelper(MainActivity.this, "SHOPPING_DB", null, 9);

helper.insert(2, "Name", "Description", "100", "Type");

Cursor cursor = helper.getValues();
cursor.moveToFirst();

String[] columns = new String[]{DatabaseHelper.ID, DatabaseHelper.ITEM_NAME, DatabaseHelper.DESCRIPTION,
DatabaseHelper.PRICE, DatabaseHelper.TYPE};
int[] intArray = new int[]{android.R.id.text1};

SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(MainActivity.this, android.R.layout.simple_list_item_1, cursor, columns, intArray, 0);

ListView listView = (ListView) findViewById(R.id.shopping_list_view);
listView.setAdapter(simpleCursorAdapter);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search_options_menu, menu);
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class DBAssetHelper extends SQLiteAssetHelper {

private static final String DATABASE_NAME = "SHOPPING_DB";
private static final int DATABASE_VERSION = 7;
private static final int DATABASE_VERSION = 9;

public DBAssetHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/search"
android:title="Search"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="collapseActionView"/>
</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="Search for something..."/>