我在小型应用程序中遇到WebViews问题.我有相关的Web视图,其布局中包含正确的信息,并且我有直接来自Android开发者网站的示例代码,这些示例代码对我不起作用.
该错误是围绕:
findViewById(R.id.webview)方法.
具有事件监听器的类:
package com.bignerdranch.android.transitionexample;
import android.app.Fragment;
import android.os.Bundle;
import android.transition.Scene;
import android.transition.TransitionManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.widget.Button;
import com.bignerdranch.android.transitionexample.R;
/**
* A placeholder fragment containing a simple view.
*/
public class TransitionFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_transition_scene_1, container, false);
final Scene scene = Scene.getSceneForLayout(container, R.layout.fragment_transition_scene_2, getActivity());
Button goButton = (Button)rootView.findViewById(R.id.goButton);
goButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TransitionManager.go(scene);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
Log.d("","Loading Finished");
}
});
return rootView;
}
}
布局:
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scene"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.bignerdranch.android.transitionexample.TransitionFragment">
android:id="@+id/textView"
android:text="@string/hello_world"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:text="@string/hello_world"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="@android:dimen/thumbnail_height"
android:layout_weight="1.43" />