我有一个片段活动,左侧有一个 ListFragment,右侧有一个带有 WebView 的片段。该功能工作正常,但我想在网页完成加载时显示一个显示“正在加载...”的进度对话框。我怎样才能完成这个看似微不足道的任务?
下面是我的代码:
public class ArticleListActivity extends FragmentActivity implements
ArticleListFragment.OnArticleSelectedListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.articlelist_fragment);
}
public void onArticleSelected(String contentLink) {
ArticleViewerFragment viewer = (ArticleViewerFragment) getSupportFragmentManager()
.findFragmentById(R.id.articleview_fragment);
if (viewer == null || !viewer.isInLayout()) {
Intent showContent = new Intent(getApplicationContext(),
ArticleViewerActivity.class);
showContent.setData(Uri.parse(contentLink));
startActivity(showContent);
} else {
viewer.updateUrl(contentLink);
}
}
}
这是我的 FragmentActivity
public class ArticleViewerActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.articleview_fragment);
Intent launchingIntent = getIntent();
String content = launchingIntent.getData().toString();
ArticleViewerFragment viewer = (ArticleViewerFragment) getSupportFragmentManager()
.findFragmentById(R.id.articleview_fragment);
viewer.updateUrl(content);
}
}
这是我的片段
public class ArticleViewerFragment extends Fragment {
private ProgressDialog progressBar;
private WebView viewer = null;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
viewer = (WebView) inflater.inflate(R.layout.webview_layout, container, false);
viewer.loadUrl("file:///android_asset/default.html");
return viewer;
}
public void updateUrl(String newUrl) {
if (viewer != null) {
viewer.loadUrl(newUrl);
}
}
}