2013-12-07 4 views
2

Я хочу, чтобы добавить индикатор прогресса в моей class, но я только нашел для Extend Activity и я использую ящик так FragmentДобавить ProgressBar WebView в фрагменте

Это мой код, как добавить progressbar

public class HomeFragment extends Fragment { 

    public HomeFragment(){} 

    WebView myWebView; 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
      Bundle savedInstanceState) { 


     View root = inflater.inflate(R.layout.fragment_home, container, false); 
     myWebView = (WebView) root.findViewById(R.id.webview); 
     myWebView.setWebViewClient(new WebViewClient()); 
     myWebView.loadUrl("http://192.168.1.11/MAMP/isn/profil.php"); 



     return root; 

    } 

} 

ответ

4

мне нужно добавить ProgressBar в моем макете и я показать/скрыть это от самого фрагмента

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    rootView = inflater.inflate(R.layout.fragmentT4, container, false); 
    progressBarT4 = (ProgressBar) rootView.findViewById(R.id.progressBarT4); 

    webView = (WebView) rootView.findViewById(R.id.webViewT4); 
    webView.setWebViewClient(new WebViewClient()); 
    webView.setWebChromeClient(new WebChromeClient() { 
     public void onProgressChanged(WebView view, int progress) { 
      progressBarT4.setVisibility(View.VISIBLE); 
      progressBarT4.setProgress(progress); 
      if (progress == 100) { 
       progressBarT4.setVisibility(View.GONE); // Make the bar disappear after URL is loaded 
      } 
     } 
    }); 

    progressBarT4.setVisibility(View.VISIBLE); 
    webView.loadUrl("http://192.168.1.11/MAMP/isn/profil.php"); 
} 

Вам нужно будет к дд несколько переменных в объявлении класса

public class FragmentT4 extends Fragment { 
    private View rootView = null; 
    private WebView webView; 
    private ProgressBar progressBarT4 = null; 
    ... 

Также следите за макет и убедитесь, что у вас есть ProgressBar на верхней часть Webview

+0

где находится ?? CustomWebChromeClient() не может найти –

+0

Просто используйте WebChromeClient() - извините, что у меня был openFileChoosed, настроенный и расширенный как защищенный класс. CustomWebChromeClient расширяет WebChromeClient. Я обновил андер. – theczechsensation

Смежные вопросы