mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
Search button functionality
This commit is contained in:
parent
c948444f73
commit
af2bc752a5
@ -20,28 +20,31 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
<!-- Enable Searching from main activity -->
|
<!-- Enable Searching from main activity -->
|
||||||
<meta-data
|
<!-- <meta-data-->
|
||||||
android:name="android.app.default_searchable"
|
<!-- android:name="android.app.default_searchable"-->
|
||||||
android:value=".SearchableActivity" />
|
<!-- android:value=".SearchResults" />-->
|
||||||
</activity> <!-- Searchable activity used to handle searches -->
|
</activity> <!-- Searchable activity used to handle searches -->
|
||||||
<activity
|
<activity
|
||||||
android:name=".SearchableActivity"
|
android:name=".SearchableActivity"
|
||||||
android:label="@string/title_activity_search"
|
android:label="@string/title_activity_search"
|
||||||
android:theme="@style/AppTheme.NoActionBar">
|
android:theme="@style/AppTheme.NoActionBar">
|
||||||
<intent-filter>
|
<!-- <intent-filter>-->
|
||||||
<action android:name="android.intent.action.SEARCH" />
|
<!-- <action android:name="android.intent.action.SEARCH" />-->
|
||||||
</intent-filter>
|
<!-- </intent-filter>-->
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".SearchResults"
|
android:name=".SearchResults"
|
||||||
android:label=""
|
android:label=""
|
||||||
android:theme="@style/AppTheme.NoActionBar"
|
android:theme="@style/AppTheme.NoActionBar"
|
||||||
>
|
>
|
||||||
</activity>
|
<!-- <intent-filter>-->
|
||||||
|
<!-- <action android:name="android.intent.action.SEARCH" />-->
|
||||||
|
<!-- </intent-filter>-->
|
||||||
|
|
||||||
<meta-data
|
<!-- <meta-data-->
|
||||||
android:name="android.app.searchable"
|
<!-- android:name="android.app.searchable"-->
|
||||||
android:resource="@xml/searchable" />
|
<!-- android:resource="@xml/searchable" />-->
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@ -56,6 +56,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// onSearchRequested();
|
// onSearchRequested();
|
||||||
Intent intent = new Intent(MainActivity.this, SearchResults.class);
|
Intent intent = new Intent(MainActivity.this, SearchResults.class);
|
||||||
|
// Send them to the search results page
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);
|
overridePendingTransition(R.anim.enter_from_left, R.anim.exit_from_left);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
|
|
||||||
|
import android.app.SearchManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@ -11,7 +12,9 @@ import androidx.appcompat.widget.Toolbar;
|
|||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class SearchResults extends AppCompatActivity {
|
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 searchView = (SearchView) findViewById(R.id.searchBar);
|
||||||
// searchView.requestFocus();
|
// searchView.requestFocus();
|
||||||
searchView.setIconified(false);
|
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);
|
// FloatingActionButton fab = findViewById(R.id.fab);
|
||||||
// fab.setOnClickListener(new View.OnClickListener() {
|
// fab.setOnClickListener(new View.OnClickListener() {
|
||||||
// @Override
|
// @Override
|
||||||
@ -50,4 +78,9 @@ public class SearchResults extends AppCompatActivity {
|
|||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_from_right);
|
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_from_right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ListView doSearch(String query) {
|
||||||
|
System.out.println(query);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user