Autore Topic: inserire webview  (Letto 481 volte)

Offline manu

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
inserire webview
« il: 16 Maggio 2014, 16:53:27 CEST »
0
Ciao a tutti
Volevo sapere se era possibile inserire una webview dentro questo progetto?
https://github.com/gabrielemariotti/androiddev/tree/master/ActionBarCompatEclipse

Ho provato ma nel file MainActivity.java mi restituisce questo errore:
Duplicate method onCreate(Bundle) in type MainActivity
come posso risolverlo?



trovate i miei file qui
https://github.com/manucnx/app

(è il mio primo progetto)
Grazie

Offline giuseppesorce

  • Utente junior
  • **
  • Post: 90
  • Respect: +6
    • Google+
    • warpmobile_it
    • Mostra profilo
  • Dispositivo Android:
    Nexus 6,Nexus 5,Nexus 4, Galaxy Nexus, Nexus s, Nexus One,Htc Wildfire S, Nexus 7... etc
  • Sistema operativo:
    Ubuntu 14.04
Re:inserire webview
« Risposta #1 il: 21 Maggio 2014, 16:41:36 CEST »
0
In efffetti dall' immagine vedo che ci sono due metodi onCreate e non è possibile usare due metodi con la stessa firma, puoi usare 2 metodi con nome uguale solo cambiando il tipo di parametro almeno.

Puoi per favore inserire tutto il codice e non l' immagine? Dall' immagine non possiamo aiutarti. Cmq la WebView devi inserirla nel layout dell' activity e richiamarla per esempio nell' onCreate, non creando due metodi ma inserendo altro codice nel primo onCreate
The code is joy and passion but it has a high degree of suffering

Offline manu

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
Re:inserire webview
« Risposta #2 il: 21 Maggio 2014, 17:07:05 CEST »
0
Ciao Giuseppe
Grazie per il supporto  :)
ho messo i file qui
https://github.com/manucnx/app[/url][/color]
cmq ecco il codice


/*******************************************************************[size=78%]*******************************************************************************/[/size]
package com.eample.ActionBarCompatEclipse;


import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;


public class MainActivity extends ActionBarActivity {


   private ListView mDrawerList;
   private DrawerLayout mDrawer;
   private CustomActionBarDrawerToggle mDrawerToggle;
   private String[] menuItems;
   private WebView mWebView;


   private String url = "[url]http://google.it";


   


   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
       //carichiamo la webview dentro il layout specificato
        mWebView = (WebView) findViewById(R.id.webview);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.getSettings().setLoadsImagesAutomatically(true);      
      //carichiamo finalmete la url
      mWebView.setWebViewClient(new WebViewClient());
      mWebView.loadUrl(url);
   


   
      
      setContentView(R.layout.activity_main_drawer);
       //carichiamo la webview dentro il layout specificato
        mWebView = (WebView) findViewById(R.id.webview);
      mWebView.getSettings().setJavaScriptEnabled(true);
      mWebView.getSettings().setLoadsImagesAutomatically(true);      
      //carichiamo finalmete la url
      mWebView.setWebViewClient(new WebViewClient());
      mWebView.loadUrl(url);
   }
   
   protected void onCreate1(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_drawer);
      // enable ActionBar app icon to behave as action to toggle nav drawer
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setHomeButtonEnabled(true);


      mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);


      // set a custom shadow that overlays the main content when the drawer
      // opens
      mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);


      _initMenu();
      mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
      mDrawer.setDrawerListener(mDrawerToggle);


   }


   private void _initMenu() {
      NsMenuAdapter mAdapter = new NsMenuAdapter(this);


      // Add Header
      mAdapter.addHeader(R.string.ns_menu_main_header);


      // Add first block


      menuItems = getResources().getStringArray(
            R.array.ns_menu_items);
      String[] menuItemsIcon = getResources().getStringArray(
            R.array.ns_menu_items_icon);


      int res = 0;
      for (String item : menuItems) {


         int id_title = getResources().getIdentifier(item, "string",
               this.getPackageName());
         int id_icon = getResources().getIdentifier(menuItemsIcon[res],
               "drawable", this.getPackageName());


         NsMenuItemModel mItem = new NsMenuItemModel(id_title, id_icon);
         if (res==1) mItem.counter=12; //it is just an example...
         if (res==3) mItem.counter=3; //it is just an example...
         mAdapter.addItem(mItem);
         res++;
      }


      mAdapter.addHeader(R.string.ns_menu_main_header2);


      mDrawerList = (ListView) findViewById(R.id.drawer);
      if (mDrawerList != null)
         mDrawerList.setAdapter(mAdapter);
      
      mDrawerList.setOnItemClickListener(new DrawerItemClickListener());


   }


   @Override
   protected void onPostCreate(Bundle savedInstanceState) {
      super.onPostCreate(savedInstanceState);
      // Sync the toggle state after onRestoreInstanceState has occurred.
      mDrawerToggle.syncState();
   }


   @Override
   public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
      mDrawerToggle.onConfigurationChanged(newConfig);
   }
   
   @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }


    /* Called whenever we call invalidateOptionsMenu() */
    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        // If the nav drawer is open, hide action items related to the content view
        boolean drawerOpen = mDrawer.isDrawerOpen(mDrawerList);
        menu.findItem(R.id.action_save).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }


   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
      /*
       * The action bar home/up should open or close the drawer.
       * ActionBarDrawerToggle will take care of this.
       */
      if (mDrawerToggle.onOptionsItemSelected(item)) {
         return true;
      }


      // Handle your other action bar items...
      return super.onOptionsItemSelected(item);
   }


   private class CustomActionBarDrawerToggle extends ActionBarDrawerToggle {


      public CustomActionBarDrawerToggle(Activity mActivity,DrawerLayout mDrawerLayout){
         super(
             mActivity,
             mDrawerLayout,
             R.drawable.ic_drawer,
             R.string.ns_menu_open,
             R.string.ns_menu_close);
      }


      @Override
      public void onDrawerClosed(View view) {
         getSupportActionBar().setTitle(getString(R.string.ns_menu_close));
         supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }


      @Override
      public void onDrawerOpened(View drawerView) {
         getSupportActionBar().setTitle(getString(R.string.ns_menu_open));
         supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
      }
   }
   
   private class DrawerItemClickListener implements ListView.OnItemClickListener {


      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position,
            long id) {
         // Highlight the selected item, update the title, and close the drawer
         // update selected item and title, then close the drawer
           mDrawerList.setItemChecked(position, true);
           String text= "menu click... should be implemented";
           Toast.makeText(MainActivity.this, text , Toast.LENGTH_LONG).show();
           //You should reset item counter
           mDrawer.closeDrawer(mDrawerList);
         
      }
      
   }
   public void goBack(View v)
   {
      mWebView.goBack();
   }


   public void goForward(View v)
   {
      mWebView.goForward();
   }


}


Offline giuseppesorce

  • Utente junior
  • **
  • Post: 90
  • Respect: +6
    • Google+
    • warpmobile_it
    • Mostra profilo
  • Dispositivo Android:
    Nexus 6,Nexus 5,Nexus 4, Galaxy Nexus, Nexus s, Nexus One,Htc Wildfire S, Nexus 7... etc
  • Sistema operativo:
    Ubuntu 14.04
Re:inserire webview
« Risposta #3 il: 21 Maggio 2014, 17:22:27 CEST »
0
Allora hai questi due metodi

Codice (Java): [Seleziona]
@Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                 //carichiamo la webview dentro il layout specificato
        mWebView = (WebView) findViewById(R.id.webview);
                mWebView.getSettings().setJavaScriptEnabled(true);
                mWebView.getSettings().setLoadsImagesAutomatically(true);              
                //carichiamo finalmete la url
                mWebView.setWebViewClient(new WebViewClient());
                mWebView.loadUrl(url);
   

       
               
                setContentView(R.layout.activity_main_drawer);
                 //carichiamo la webview dentro il layout specificato
        mWebView = (WebView) findViewById(R.id.webview);
                mWebView.getSettings().setJavaScriptEnabled(true);
                mWebView.getSettings().setLoadsImagesAutomatically(true);              
                //carichiamo finalmete la url
                mWebView.setWebViewClient(new WebViewClient());
                mWebView.loadUrl(url);
        }
       
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main_drawer);
                // enable ActionBar app icon to behave as action to toggle nav drawer
                getSupportActionBar().setDisplayHomeAsUpEnabled(true);
                getSupportActionBar().setHomeButtonEnabled(true);

                mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

                // set a custom shadow that overlays the main content when the drawer
                // opens
                mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

                _initMenu();
                mDrawerToggle = new CustomActionBarDrawerToggle(this, mDrawer);
                mDrawer.setDrawerListener(mDrawerToggle);

        }

Li devi unire e decidere cosa fare. Non puoi settare il contenuto due volte:

Codice (Java): [Seleziona]
setContentView(R.layout.activity_main);
e poi

Codice (Java): [Seleziona]
               
                setContentView(R.layout.activity_main_drawer);

il secondo sovrascrive il primo.

Quindi fammi capire che Layout vuoi. Una webview a tutto per lo spazio disponibile e il Drawer Menu ?



The code is joy and passion but it has a high degree of suffering

Offline manu

  • Nuovo arrivato
  • *
  • Post: 3
  • Respect: 0
    • Mostra profilo
Re:inserire webview
« Risposta #4 il: 21 Maggio 2014, 17:34:39 CEST »
0
Si esatto, vorrei la webview e il Drawer Menu dove inserire dei bottoni/link che rimandano a delle pagine del sito




Grazie