如何实现左边四个不同按钮切换时右边显示不同内容。

解决方案 »

  1.   

    在xml文件中有webview和按钮。在activity name.java中试试下面的代码
    public class yourActivityname extends Activity implements OnClickListener {    private WebView yourWebView;    
        private Button button1, button2;     @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
                // assign reference of xml activity contents to your class variables
            yourWebView = (WebView) findViewById(R.id.web);
                button1 = (Button) findViewById(R.id.button1);   
                button2 = (Button) findViewById(R.id.button2);
            String url = "https:/www.google.com";
            yourWebView.getSettings().setJavaScriptEnabled(true);
               //load default url
               loadWebContents(url);    }
    创建一个方法,加载web和调用onclick
    private void loadWebContents(String url){
            yourWebView.setWebChromeClient(new WebChromeClient() {
                public void onProgressChanged(WebView view, int progress) {            }
            });        yourWebView.loadUrl(url);
        }
    on click方法
    public void onClick(View v) {
            switch (v.getId()) {
            case R.id.button1:
                loadWebContents("www.msn.com");
                break;
            case R.id.restoreBtn:
                loadWebContents("www.gmail.com");
                break;
            }    }
    }
      

  2.   

    使用android 的扩展库android-support-v4的Fragment来进行布局~当然在3.0就不需要扩展库了
    可以看下Fragment自带的例子~