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
1 change: 1 addition & 0 deletions starter-code/ShoppingListWithSearch/.idea/.name

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

22 changes: 22 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/compiler.xml

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

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

18 changes: 18 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/gradle.xml

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

62 changes: 62 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/misc.xml

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

9 changes: 9 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/modules.xml

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

12 changes: 12 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/runConfigurations.xml

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

6 changes: 6 additions & 0 deletions starter-code/ShoppingListWithSearch/.idea/vcs.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 @@ -11,9 +11,13 @@
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEARCH"/>

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ly.generalassemb.drewmahrt.shoppinglistwithsearch;

import android.app.DownloadManager;
import android.app.SearchManager;
import android.app.SearchableInfo;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
Expand All @@ -12,6 +15,8 @@
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
private ListView mShoppingListView;
Expand All @@ -28,12 +33,40 @@ protected void onCreate(Bundle savedInstanceState) {

mCursorAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1,cursor,new String[]{ShoppingSQLiteOpenHelper.COL_ITEM_NAME},new int[]{android.R.id.text1},0);
mShoppingListView.setAdapter(mCursorAdapter);

handleIntent (getIntent() );

}

@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
handleIntent(intent);
}

private void handleIntent( Intent intent){
if(Intent.ACTION_SEARCH.equals(intent.getAction())){
String query= intent.getStringExtra(SearchManager.QUERY);
Toast.makeText(MainActivity.this, "You are searching for " + query, Toast.LENGTH_SHORT).show();


Cursor cursor= ShoppingSQLiteOpenHelper.getInstance(this).getShoppingList2(query);
mCursorAdapter.swapCursor(cursor);


}
}

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main_menu, menu);
menuInflater.inflate(R.menu.search_options_menu, menu);
SearchManager searchManager= (SearchManager) getSystemService(SEARCH_SERVICE);
SearchView searchView= (SearchView)menu.findItem(R.id.search).getActionView();


SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(info);

return super.onCreateOptionsMenu(menu);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,21 @@ private void loadShoppingInfo(SQLiteDatabase db) throws IOException {
reader.close();
}
}

public Cursor getShoppingList2(String query){

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.query(SHOPPING_LIST_TABLE_NAME, // a. table
SHOPPING_COLUMNS, // b. column names
COL_ITEM_NAME + " LIKE ?", // c. selections
new String[]{query + "%"}, // d. selections args
null, // e. group by
null, // f. having
null, // g. order by
null); // h. limit

return cursor;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?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|ifRoom"
app:actionViewClass="android.support.v7.widget.SearchView"/>

</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?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 Groceries..."
/>