我将添加什么代码,以便在按下菜单按钮刷新时它会刷新我的应用程序中的 webview。?
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView WV = (WebView) findViewById(R.id.webView1);
WV.getSettings().setJavaScriptEnabled(true);
WV.loadUrl("http://home.btconnect.com/MrJFisher/");
}
@Override
public boolean onCreateOptionsMenu (Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId() == R.id.item1){
WebView.reload();
}
return super.onOptionsItemSelected(item);
}
};
初学者。所以我道歉。