First of all see what I have done yet.
This is my menu.xml file.
<?xml version="1.0" encoding="utf-8"?>
<item android:id="@+id/friend"
android:title="friend_list"
android:icon="@drawable/friends"
android:showAsAction="ifRoom"/>
<item android:id="@+id/search"
android:title="search"
android:icon="@drawable/search"
android:showAsAction="always|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
<item android:id="@+id/profile"
android:title="@string/profile" />
<item android:id="@+id/settings"
android:title="@string/settings" />
<item android:id="@+id/logout"
android:title="@string/logout" />
</menu>
This is my onCreateOptionMenu
function. I haven't changed it.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
This is my onOptionsItemSelected
function.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.friend:
showFragment(FRIENDLIST, true);
((FriendListActivity)fragments[FRIENDLIST]).populateFriendList(this, resultObj.HomeData.Friends);
return true;
case R.id.logout:
showFragment(SETTINGS, true);
return true;
case android.R.id.home:
showFragment(HOME, false);
return true;
case R.id.search:
if(!fragments[FRIENDLIST].isVisible())
{
showFragment(FRIENDLIST, true);
((FriendListActivity)fragments[3]).populateFriendList(this, resultObj.HomeData.Friends);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
When I click on search menu item, It expands and show textview to write. I want the textChanged event of that textView.
http://developer.android.com/training/search/setup.html
Go through this. It explains how to setup search view in actionbar and add textchangelistner for searchview in onCreateOptionsMenu.