Open AdnanSattar opened 6 years ago
Hello, suggestions not showing. compileSdkVersion 26 buildToolsVersion '26.0.2' minSdkVersion 19 targetSdkVersion 26 implementation 'com.miguelcatalan:materialsearchview:1.4.0'
res/layout/toolbar.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/container" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"> <!-- Must be last for right layering display --> <FrameLayout android:id="@+id/toolbar_container" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar1" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/white"> <ImageView android:id="@+id/Home" android:layout_width="35dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@drawable/logo" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"/> </android.support.v7.widget.Toolbar> <com.miguelcatalan.materialsearchview.MaterialSearchView android:id="@+id/search_view" android:layout_width="match_parent" android:layout_height="wrap_content"/> </FrameLayout> </FrameLayout>
Home_activity
public class Home extends AppCompatActivity { private MaterialSearchView searchView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_home); Toolbar toolbar = findViewById(R.id.toolbar1); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowTitleEnabled(false); searchView = findViewById(R.id.search_view); searchView.setVoiceSearch(false); //searchView.setCursorDrawable(R.drawable.custom_cursor); searchView.setEllipsize(true); // searchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions)); searchView.setSuggestions(new String[]{"aa","ab"}); searchView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { } }); searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { SearchProduct(getApplicationContext(), query); Toast.makeText(getApplicationContext(),"Query: " + query,Toast.LENGTH_LONG).show(); return false; } @Override public boolean onQueryTextChange(String newText) { searchView.showSuggestions(); return false; } }); searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() { @Override public void onSearchViewShown() { searchView.showSuggestions(); } @Override public void onSearchViewClosed() { //Do some magic } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem search_item = menu.findItem(R.id.action_search); searchView.setMenuItem(search_item); MenuItem cart_item = menu.findItem(R.id.action_basket); //searchView.setMenuItem(cart_item); MenuItem location_item = menu.findItem(R.id.action_Location); // searchView.setMenuItem(location_item); /*MenuItem menu_item = menu.findItem(R.id.action_menu); searchView.setMenuItem(menu_item);*/ return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_search: searchView.showSearch(true); searchView.setVisibility(View.VISIBLE); Toast.makeText(this, "You have selected Bookmark Menu", Toast.LENGTH_SHORT).show(); return true; case R.id.action_basket: if (myApp.getCart().size() > 0) { Intent intent = new Intent(getApplicationContext(), CheckOut.class); intent.putExtra("cat", (Serializable) dataset); startActivity(intent); } else { Toast.makeText(getApplicationContext(), "Cart is Empty", Toast.LENGTH_LONG).show(); } return true; case R.id.action_Location: Intent intent = new Intent(getApplicationContext(), Pickup.class); intent.putExtra("cat", (Serializable) dataset); startActivity(intent); return true; /*case R.id.action_menu: Toast.makeText(this, "You have selected Share Menu", Toast.LENGTH_SHORT).show(); return true;*/ default: return super.onOptionsItemSelected(item); } } @Override public void onBackPressed() { if (searchView.isSearchOpen()) { searchView.closeSearch(); } else { super.onBackPressed(); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MaterialSearchView.REQUEST_VOICE && resultCode == RESULT_OK) { ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); if (matches != null && matches.size() > 0) { String searchWrd = matches.get(0); if (!TextUtils.isEmpty(searchWrd)) { searchView.setQuery(searchWrd, false); } } return; } super.onActivityResult(requestCode, resultCode, data); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); } }
Home_activity layout
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFFF" tools:context=".Home"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <include android:id="@+id/toolbar" layout="@layout/toolbar_new"> </include> </LinearLayout> </RelativeLayout>
Hope some one will point out the issue!
The same problem
mismo problema alguna solucion?
Hello, suggestions not showing. compileSdkVersion 26 buildToolsVersion '26.0.2' minSdkVersion 19 targetSdkVersion 26 implementation 'com.miguelcatalan:materialsearchview:1.4.0'
res/layout/toolbar.xml
Home_activity
Home_activity layout
Hope some one will point out the issue!