基本适配器类
builder.setPositiveButton("View Full News Source", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
android.support.v4.app.Fragment fragment = new Source();
FragmentManager fm = fragment.getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Bundle bundle = new Bundle();
bundle.putString("url", source.get(position).toString()); //key and value
fragment.setArguments(bundle);
ft.replace(R.id.frameLayout, fragment);
ft.commit();
}
});
builder.show();
源片段
public class Source extends Fragment {
private WebView webView;
private ImageView back;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
webView = container.findViewById(R.id.webview);
back = container.findViewById(R.id.back);
return inflater.inflate(R.layout.source, container, false);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
String url = getArguments().getString("url");
Toast.makeText(getActivity(), "url" + url, Toast.LENGTH_SHORT).show();
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
settings.supportZoom();
settings.getBuiltInZoomControls();
settings.getDisplayZoomControls();
webView.setWebChromeClient(new WebChromeClient());
webView.loadUrl(url);
}
}
LOGCAT
java.lang.NullPointerException 在akaxay.com.crynewsx.CustomAdapter $ 1 $ 1.onClick(CustomAdapter.java:106) 在android.support.v7.app.AlertController $ ButtonHandler.handleMessage(AlertController.java:166) 在android.os.Handler.dispatchMessage(Handler.java:107) 在android.os.Looper.loop(Looper.java:194) 在android.app.ActivityThread.main(ActivityThread.java:5391) 在java.lang.reflect.Method.invokeNative(本机方法) 在java.lang.reflect.Method.invoke(Method.java:525) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:833) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 在dalvik.system.NativeStart.main(本机方法)