Search button functionality

This commit is contained in:
Clayton Wilson 2020-09-24 15:11:11 -04:00
parent c948444f73
commit af2bc752a5
3 changed files with 47 additions and 10 deletions

View File

@ -20,28 +20,31 @@
</intent-filter>
<!-- Enable Searching from main activity -->
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchableActivity" />
<!-- <meta-data-->
<!-- android:name="android.app.default_searchable"-->
<!-- android:value=".SearchResults" />-->
</activity> <!-- Searchable activity used to handle searches -->
<activity
android:name=".SearchableActivity"
android:label="@string/title_activity_search"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.SEARCH" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".SearchResults"
android:label=""
android:theme="@style/AppTheme.NoActionBar"
>
</activity>
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.SEARCH" />-->
<!-- </intent-filter>-->
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<!-- <meta-data-->
<!-- android:name="android.app.searchable"-->
<!-- android:resource="@xml/searchable" />-->
</activity>
</application>
</manifest>

View File

@ -56,6 +56,7 @@ public class MainActivity extends AppCompatActivity {
public void onClick(View v) {
// onSearchRequested();
Intent intent = new Intent(MainActivity.this, SearchResults.class);
// Send them to the search results page
startActivity(intent);
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);

View File

@ -1,5 +1,6 @@
package com.example.listify;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
@ -11,7 +12,9 @@ import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.Toast;
public class SearchResults extends AppCompatActivity {
@ -31,10 +34,35 @@ public class SearchResults extends AppCompatActivity {
}
});
// Intent intent = getIntent();
// if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
// String query = intent.getStringExtra(SearchManager.QUERY);
// Toast.makeText(this, query, Toast.LENGTH_SHORT).show();
// doSearch();
// }
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
SearchView searchView = (SearchView) findViewById(R.id.searchBar);
// searchView.requestFocus();
searchView.setIconified(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
doSearch(query);
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
// searchView.setSearchableInfo(searchManager.getSearchableInfo((getComponentName())));
// searchView.setSubmitButtonEnabled(true);
// FloatingActionButton fab = findViewById(R.id.fab);
// fab.setOnClickListener(new View.OnClickListener() {
// @Override
@ -50,4 +78,9 @@ public class SearchResults extends AppCompatActivity {
super.onBackPressed();
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_from_right);
}
private ListView doSearch(String query) {
System.out.println(query);
return null;
}
}