android - I can't put a listener to hamburger button and the right buttons clicks in a Floating Search View using Ari Morty library -
i'm beginner, i'm trying implement floating search view library: floating search view
i need connect hamburger button drawer view , right buttons actions.
listen hamburger button clicks:
msearchview.setonleftmenuclicklistener( new floatingsearchview.onleftmenuclicklistener() { ...} );
to connect navigationdrawer hamburger button:
msearchview.attachnavigationdrawertomenubutton(mdrawerlayout);
listen item selections
msearchview.setonmenuitemclicklistener(new floatingsearchview.onmenuitemclicklistener() { @override public void onmenuitemselected(menuitem item) { } });
there examples when put on code, bring me error. maybe problem don't know should write it.
please, me, have been searching , trying weeks.
so here complete example:
androidmanifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.j2ko.webviewapp"> <uses-permission android:name="android.permission.internet" /> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".floatingsearchactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest>
floatingsearchactivity
layout :
<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- main content view --> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context="com.j2ko.webviewapp.floatingsearchactivity" tools:showin="@layout/activity_floating_search"> <com.arlib.floatingsearchview.floatingsearchview android:id="@+id/floating_search_view" android:layout_width="match_parent" android:layout_height="match_parent" app:floatingsearch_searchbarmarginleft="10dp" app:floatingsearch_searchbarmargintop="10dp" app:floatingsearch_searchbarmarginright="10dp" app:floatingsearch_searchhint="search..." app:floatingsearch_suggestionslistanimduration="250" app:floatingsearch_showsearchkey="false" app:floatingsearch_leftactionmode="showhamburger" app:floatingsearch_close_search_on_keyboard_dismiss="true"/> </relativelayout> <!-- navigation drawer --> <linearlayout android:id="@+id/left_drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start" android:orientation="vertical" android:divider="@android:color/transparent" android:dividerheight="0dp" android:background="#c46ec4"> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="drower item 1"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="drower item 2"/> <textview android:layout_width="match_parent" android:layout_height="wrap_content" android:text="drower item 3"/> </linearlayout> </android.support.v4.widget.drawerlayout>
and floatingsearchactivity
:
package com.j2ko.webviewapp; import android.os.bundle; import android.os.parcel; import android.os.parcelable; import android.support.v4.widget.drawerlayout; import android.support.v7.app.appcompatactivity; import com.arlib.floatingsearchview.floatingsearchview; import com.arlib.floatingsearchview.suggestions.model.searchsuggestion; import java.util.arraylist; import java.util.list; public class floatingsearchactivity extends appcompatactivity { floatingsearchview msearchview; drawerlayout mdrawerlayout; //dummy data search suggestions private static final list<string> some_hardcoded_data; static { some_hardcoded_data = new arraylist<>(); some_hardcoded_data.add("one"); some_hardcoded_data.add("two"); some_hardcoded_data.add("three"); some_hardcoded_data.add("four"); } //this illustration how populate suggestions private static class simplesuggestions implements searchsuggestion { private final string mdata; public simplesuggestions(string string) { mdata = string; } @override public string getbody() { return mdata; } @override public int describecontents() { return 0; } @override public void writetoparcel(parcel dest, int flags) { dest.writestring(mdata); } public static final parcelable.creator<simplesuggestions> creator = new parcelable.creator<simplesuggestions>() { public simplesuggestions createfromparcel(parcel in) { return new simplesuggestions(in); } public simplesuggestions[] newarray(int size) { return new simplesuggestions[size]; } }; private simplesuggestions(parcel in) { mdata = in.readstring(); } } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_floating_search); mdrawerlayout = (drawerlayout) findviewbyid(r.id.drawer_layout); msearchview = (floatingsearchview) findviewbyid(r.id.floating_search_view); msearchview.setonquerychangelistener(new floatingsearchview.onquerychangelistener() { @override public void onsearchtextchanged(string oldquery, final string newquery) { list<searchsuggestion> list = new arraylist<searchsuggestion>(); //emulating search on dummy data (string item : some_hardcoded_data) { if (item.contains(newquery)) { list.add(new simplesuggestions(item)); } } msearchview.swapsuggestions(list); } }); //now search view controlling drawer open/closer msearchview.attachnavigationdrawertomenubutton(mdrawerlayout); } }
the result following :
Comments
Post a Comment