2013-09-28 65 views
0

沒有其他方式詢問此問題。我正在使用android工作室,我已經設置了一個可滾動的滑動選項卡的應用程序,我設置了4個選項卡,我希望在選項卡2中有一個網頁加載,我有一個webview類和一個Internet類,我已設置清單以允許Internet ,但我沒有在我的佈局文件上的按鈕,並設置onlcik listner加載我的webpge,我想知道的是我如何加載webview時,我刷卡到第2頁,而不使用按鈕希望在沒有按鈕的情況下在幻燈片2中打開webview

代碼如下

public DummySectionFragment() { 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 
     if ((getArguments().getInt(ARG_SECTION_NUMBER)==1)) { 
      View view = inflater.inflate(R.layout.phones, container, false); 

      return view; 

     } 

     if ((getArguments().getInt(ARG_SECTION_NUMBER)==2)) { 
      View view = inflater.inflate(R.layout.webload, container, false); 

      Button webButton = (Button)view.findViewById(R.id.view7); 

      webButton.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
        Intent intent = new Intent(); 
        intent.setClass(getActivity(), Internet.class); 
        startActivity(intent); 
       } 
      }); 

      return view; 
     } 
所有的

`

+0

任何信息都將是巨大的,請傢伙..三江源 – jamie

回答

1

首先,我要實現單獨的類的不同片段。當你對這些標籤的每個片段都有很多代碼時,你的代碼會有點亂,難以閱讀和維護。

然後,如果你想在你的應用程序中顯示一個網頁(所以沒有瀏覽器打開),在你的片段中,在佈局中放置一個webview,然後在代碼中獲取該webview像id的其他視圖,您需要的網址。

有關的WebView如何在這裏工作的官方文件:http://developer.android.com/reference/android/webkit/WebView.html

相關問題