I’m turning invisible my refresh button in the action bar (sherlock action bar). But, I don’t know how to call the actionbar update (onPrepareOptionsMenu() or InvalidateOptionsMenu()) inside my makeupdate() function (I need this call inside the function). I’ve been search in stackoverflow and google for hours… tested all and get nothing…
My makeupdate() function:
public void makeupdate(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
MenuItem item = menu.findItem(R.id.refresh);
item.setVisible(false);
}
EDIT – My Code
public class SiteActivity extends SherlockActivity {
private WebView myWebView;
final Activity MyActivity = this;
com.actionbarsherlock.app.ActionBar actionbar;
private Menu mainMenu;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
actionbar.setTitle("APP");
actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE);
setContentView(R.layout.site);
myWebView = (WebView) findViewById(R.id.webview);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setBuiltInZoomControls(true);
myWebView.addJavascriptInterface(new WebAppInterface(this), "Android");
myWebView.loadUrl("file:///android_asset/noconnection.html");
myWebView.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
MyActivity.setProgress(progress * 100);
}
});
myWebView.setWebViewClient(new SiteActivityClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
myWebView.loadUrl("file:///android_asset/noconnection.html");
}
});
}
public class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
@JavascriptInterface
public void makeupdateshowToast(String toast) {
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
mainMenu.findItem(R.id.refresh).setVisible(false);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getSupportMenuInflater().inflate(R.layout.actionbar, menu);
mainMenu = menu;
return true;
}
}
Your _ WebAppInterface_ class already has a Context member. Make it a SherlockActivity (better if you change the name)
and call