In my app i am working with actionbar library,(Bcz i am using api 2.2) https://github.com/johannilsson/android-actionbar
I have 6 classes in开发者_高级运维 my app. Each class contains different action items in actionbar. I want for different different action it will work differently. But in actionbar library there is single click listener for all action. But I want to call clik listener from my activity. How can i do that?
For each activity you can use code like below. You may wish to use a superclass to avoid duplication of code. For each button on the action bar you need to create an intent, and then specify that intent as the action for the button.
// Set the Action Bar title
actionBar = (ActionBar)findViewById(R.id.actionbar);
actionBar.setTitle(R.string.app_name);
// Set up the Action Bar home/icon button
actionBar.setHomeLogo(R.drawable.icon);
Intent homeIntent = new Intent(Intent.ACTION_VIEW);
homeIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
homeIntent.setClassName(context, TaxiMap.class.getName());
actionBar.setHomeAction(new ActionBar.IntentAction(this, homeIntent, R.drawable.icon));
// Add an Action Bar button
Intent actionIntent = new Intent(Intent.ACTION_VIEW);
actionIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
actionIntent.setClassName(context, TaxiMap.class.getName());
actionBar.addAction(new ActionBar.IntentAction(this, actionIntent, R.drawable.ic_action_icon));
精彩评论