I am trying to add a custom ActionView
to my ActionBar
.
I am trying to add the common refresh button. (ImageButton
, Prog
I ended up using the src code from http://code.google.com/p/styled-action-bar/.
onOptionsItemSelected()
should only be called if the action item is in the overflow menu which you should also handle. (you have it forced to "always" on action bar, so onOptionsItemSelected()
won't get called).
At onCreateOptionsMenu()
after inflating, you must setup a OnMenuItemClickListener
for the menu item.
I have found a working solution for me and I want to share it with you. It's based on the first approach of (@Macarse), with some important changes.
Important: adapt the initView method accordingly
Set an onClickListener to the ImageView (mButton)
Set loading to true & inform the Activity (MyActivity) about the click
private void initView(final Context context) {
final LayoutInflater inflator = LayoutInflater.from(context);
final View actionView = inflator.inflate(
R.layout.action_refresh_progress, this);
mProgressBar = (ProgressBar) actionView
.findViewById(R.id.action_refresh_progress);
mButton = (ImageView) actionView
.findViewById(R.id.action_refresh_button);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
setLoading(true);
((MyActivity) context).handleRefreshButtonClick();
}
});
}
React accordingly to the click in the Activity (MyActivity)
public void handleRefreshButtonClick() {
// Start refreshing...
}
I hope that my approach could save you some time finding a working solution!