1

我需要有关此代码的帮助,我需要添加 webview 代码但他无法运行,我尝试更改主要活动和 fragmenttab1 但没有。

我使用操作栏,这对我来说很难,因为我是这种方法的新手。

有知道怎么做的吗?

我的主要活动的代码是这样的:

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Obtenemos una referencia a la actionbar
    ActionBar abar = getActionBar();

        //Establecemos el modo de navegación por pestañas
    abar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    //Ocultamos el título de la actividad
    //abar.setDisplayShowTitleEnabled(false);

    //Creamos las pestañas
    ActionBar.Tab tab1 = abar.newTab().setText("Tab1");
        ActionBar.Tab tab2 = abar.newTab().setText("Map");

        //Creamos los fragments de cada pestaña
        Fragment tab1frag = new Tab1Fragment();
        Fragment tab2frag = new Tab2Fragment();

        //Asociamos los listener a las pestañas
        tab1.setTabListener(new MiTabListener(tab1frag));
        tab2.setTabListener(new MiTabListener(tab2frag));

        //Añadimos las pestañas a la action bar
        abar.addTab(tab1);
        abar.addTab(tab2);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_new:
            Log.i("ActionBar", "New!");
            return true;
        case R.id.menu_save:
            Log.i("ActionBar", "Save!");;
            return true;
        case R.id.menu_settings:
            Log.i("ActionBar", "Settings!");;
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}}

我的TabFragment1的代码是这样的:

public class Tab1Fragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment1, container, false);
}}

请帮我!!!

4

1 回答 1

0
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

 /**Fragments can initialize views from the xml layout file here or you could 
  * do it in the onCreateView() method with  
  * 
  * View fragmentView = inflater.inflate(R.layout.fragment1, container, false);
  * mVebView = (WebView) fragmentView.findViewById(R.id.webview);
  * return fragmentView; 
  *
  * Activities initialize views in the OnCreate() method
  */

mWebView = (WebView) view.findViewById(R.id.webview);
mWebView.loadUrl("http://stackoverflow.com/questions/15560698/how-place-webview-in-tab-with-action-bar-android");

}
于 2013-03-23T15:04:21.517 回答