我正在使用两个WebViews在DialogFragment内的两个选项卡中显示内容。我观察到的奇怪行为是,最初第一个选项卡打开为空白(Webview中没有任何内容)。
当我切换到第二个选项卡时,它正确地显示静态页面,然后如果我切换回第一个选项卡,它甚至也能正确地显示第一个选项卡的静态HTML。我难以弄清楚为什么它最初不加载第一个选项卡。任何想法?
当我切换到第二个选项卡时,它正确地显示静态页面,然后如果我切换回第一个选项卡,它甚至也能正确地显示第一个选项卡的静态HTML。我难以弄清楚为什么它最初不加载第一个选项卡。任何想法?
package in.co.madhur.dashclockfeedlyextension;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.LocalActivityManager;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
public class AboutDialog extends DialogFragment
{
private WebView aboutWebView, whatsNewView;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View v = LayoutInflater.from(getActivity()).inflate(R.layout.about_dialog, null);
builder.setView(v);
TabHost tabHost = (TabHost) v.findViewById(R.id.about_tab);
aboutWebView = (WebView) v.findViewById(R.id.about_webview);
whatsNewView = (WebView) v.findViewById(R.id.whatsnew_webview);
aboutWebView.setWebViewClient(new MyWebViewClient());
tabHost.setup();
builder.setNeutralButton(android.R.string.ok, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
}
});
builder.setPositiveButton(R.string.feedback_button, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", Consts.MY_EMAIL, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.feedback_button));
startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email)));
}
});
builder.setNegativeButton(R.string.rate_button, new OnClickListener()
{
@Override
public void onClick(DialogInterface dialog, int which)
{
Uri uri = Uri.parse("market://details?id="
+ getActivity().getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try
{
startActivity(goToMarket);
}
catch (ActivityNotFoundException e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="
+ getActivity().getPackageName())));
}
}
});
TabSpec aboutTab = tabHost.newTabSpec(Consts.ABOUT_TAG);
aboutTab.setIndicator(getString(R.string.action_about));
aboutTab.setContent(R.id.tab1);
//aboutTab.setContent(intent);
TabSpec whatsnewTab = tabHost.newTabSpec(Consts.WHATS_NEW_TAG);
whatsnewTab.setIndicator(getString(R.string.whatsnew_tab));
whatsnewTab.setContent(R.id.tab2);
tabHost.addTab(aboutTab);
tabHost.addTab(whatsnewTab);
tabHost.setOnTabChangedListener(new OnTabChangeListener()
{
@Override
public void onTabChanged(String tabId)
{
Log.v(App.TAG, tabId);
}
});
aboutWebView.loadUrl(Consts.ABOUT_URL);
whatsNewView.loadUrl(Consts.CHANGES_URL);
return builder.create();
}
private class MyWebViewClient extends WebViewClient
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
boolean result = false;
/* ... */
// Return false to proceed loading page, true to interrupt loading
return result;
}
}
}