I am trying to add a custom ActionView to my ActionBar.
I am trying to add the common refresh button. (ImageButton, Prog
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!