I have recently migrated from Eclipse to Android Studio and in doing so I have picked up the below error
java.lang.UnsupportedOperationException: This is not
I think you have to check your compile dependency because it is deprecated in setOnActionExpandListener 26.1.0 Check your app/build.gradle. I had faced the same issue and below config help me out. Hope this will work for you.
Here is my build.gradle config.
compileSdkVersion 25
buildToolsVersion "25.0.2"
targetSdkVersion 25
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.android.support:design:25.3.1'
MenuItemCompat.setOnActionExpandListener(item,
new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
// Return true to allow the action view to expand
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
// When the action view is collapsed, reset the query
// Return true to allow the action view to collapse
return false;
}
});
The fix thanks to ρяσѕρєя K's comment. Much appreciated mate, thank you!!
MenuItemCompat.setOnActionExpandListener(searchItem,
new MenuItemCompat.OnActionExpandListener() {
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
// Return true to allow the action view to expand
townList.setVisibility(View.VISIBLE);
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
// When the action view is collapsed, reset the query
townList.setVisibility(View.INVISIBLE);
// Return true to allow the action view to collapse
return true;
}
});