答案 0 :(得分:4)
以下是示例代码。您可以根据需要对其进行配置:
public class MainActivity extends Activity {
private Button button;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webView);
googleButton = (Button) findViewById(R.id.buttonUrl);
googleButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
});
}
}
请注意,您的清单中需要获得INTERNET权限:
<uses-permission android:name="android.permission.INTERNET" />
答案 1 :(得分:1)
您只需要在按钮的onClickListener中添加java代码:
String[] input = getInputContents(inFile);
List<String> currentBuffer = new ArrayList<String>();
List<String[]> buffers = new ArrayList<String[]>();
for(String line : input) {
if(line.equals("0")) {
buffers.add((String[])currentBuffer.toArray());
currentBuffer = new ArrayList<String>();
} else {
currentBuffer.add(line);
}
}
请参阅Android文档:Webview Android Developper