Reputation: 3362
I'm using actionBarSherlock in a device with android v 2.3.6 and I can't listen to the clicks in the ActionItems whereas this doesn't happen when I run the app in the emulator android 4.1 is there a compatibility problem? can something be done?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.barbitmap);
bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
getSupportActionBar().setBackgroundDrawable(bg);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
int itemId = item.getItemId();
System.out.println(itemId);
if(itemId==android.R.id.home){
finish();
return false;
}
return false;
}
Upvotes: 0
Views: 54
Reputation: 3255
Make sure you are importing this
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
not this
import android.view.Menu;
import android.view.MenuItem;
then use
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
switch (id)
{
case R.id.action_bar_menu_refresh:
}
}
Upvotes: 1
Reputation: 13250
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// Navigate "up" the demo structure to the launchpad activity.
// See http://developer.android.com/design/patterns/navigation.html for more.
return true;
}
return super.onOptionsItemSelected(item);
}
Upvotes: 1