Autore Topic: navigation drawer con activity  (Letto 1002 volte)

Offline twofast

  • Utente junior
  • **
  • Post: 60
  • Respect: 0
    • Mostra profilo
    • le mie app
  • Dispositivo Android:
    galaxy s3
  • Play Store ID:
    FastApp
navigation drawer con activity
« il: 22 Febbraio 2014, 16:12:34 CET »
0
Salve premetto che sono alle prime armi. Vorrei implementare in tutte l'activity il navigation drawer . Ho provato ad estendere l'activity due con l'activity del navigation drawer ma una volta aperta l'activity il navigation drawer scompare. Mi potete aiutare ?
qui posto la mia activity con il navigation drawer
Codice (Java): [Seleziona]
public class MainActivity extends Activity {
    public DrawerLayout mDrawerLayout;
    public ListView mDrawerList;
    public ActionBarDrawerToggle mDrawerToggle;

    public CharSequence mDrawerTitle;
    public CharSequence mTitle;
    public String[] mPlanetTitles;

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

        mTitle = mDrawerTitle = getTitle();
        mPlanetTitles = getResources().getStringArray(R.array.planets_array);
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        // set a custom shadow that overlays the main content when the drawer opens
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
        // set up the drawer's list view with items and click listener
        mDrawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.drawer_list_item, mPlanetTitles));
        mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

        // enable ActionBar app icon to behave as action to toggle nav drawer
        getActionBar().setDisplayHomeAsUpEnabled(true);
        getActionBar().setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
                R.string.drawer_open,  /* "open drawer" description for accessibility */
                R.string.drawer_close  /* "close drawer" description for accessibility */
                ) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
   
        if (savedInstanceState == null) {
            selectItem(0);
        }
    }

   

        @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 = mDrawerLayout.isDrawerOpen(mDrawerList);
        menu.findItem(R.id.action_websearch).setVisible(!drawerOpen);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
         // The action bar home/up action should open or close the drawer.
         // ActionBarDrawerToggle will take care of this.
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle action buttons
        switch(item.getItemId()) {
        case R.id.action_websearch:
            // create intent to perform web search for this planet
            Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
            intent.putExtra(SearchManager.QUERY, getActionBar().getTitle());
            // catch event that there's no activity to handle intent
            if (intent.resolveActivity(getPackageManager()) != null) {
                startActivity(intent);
            } else {
                Toast.makeText(this, R.string.app_not_available, Toast.LENGTH_LONG).show();
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }
    }

    /* The click listner for ListView in the navigation drawer */
    private class DrawerItemClickListener implements ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                switch (position) {
                case 0:
                selectItem(position);
               
        }
    }

    public void selectItem(int position) {
        switch(position){
       
        case 0:
               
       
        Intent intent=new Intent(MainActivity.this,Calendariojava.class);
       
        startActivity(intent);
     
        return;
       
    }
       
    }
    }
    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */


    @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);
        // Pass any configuration change to the drawer toggls
        mDrawerToggle.onConfigurationChanged(newConfig);
    }
qui invece posto il codice della mia seconda activity
Codice (Java): [Seleziona]
public class Calendariojava extends MainActivity{
        private static final int DIALOG_COSTUM_ID=2;
        int numeroassenze=0;
        TextView  testonumeroassenza;
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
setContentView(R.layout.calendario);
CalendarView calendarioorario=(CalendarView) findViewById(R.id.calendarView1);
Calendar cal = Calendar.getInstance();  
testonumeroassenza=(TextView)findViewById(R.id.numeroassenze);

calendarioorario.setOnDateChangeListener(new OnDateChangeListener() {
       
        @Override
        public void onSelectedDayChange(CalendarView view, int year, int month,
                        int dayOfMonth) {
        showDialog(DIALOG_COSTUM_ID);
        }
});
        }
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }
       
        protected Dialog onCreateDialog(int id) {
       Dialog dialog;
                switch(id) {
        case DIALOG_COSTUM_ID:
                dialog=new Dialog(Calendariojava.this);
        dialog.setContentView(R.layout.layoutcustomcalendario);
                dialog.setTitle("inserisci evento");    
                dialog.setCancelable(true);
       
        }
}
}
spero di esser stato chiaro nella mia richiesta e di aver aperto il topic nel posto giusto... ringrazio in anticipo :-)

Offline GabMarioPower

  • Moderatore globale
  • Utente senior
  • *****
  • Post: 606
  • Respect: +153
    • Github
    • Google+
    • gabrielemariotti
    • GabMarioPower
    • Mostra profilo
  • Play Store ID:
    GAB+MARIO+DEV
  • Sistema operativo:
    Ubuntu 14.04 , Win 10
Re:navigation drawer con activity
« Risposta #1 il: 22 Febbraio 2014, 17:37:14 CET »
0
Codice (Java): [Seleziona]
setContentView(R.layout.calendario);
Questo layout contiene il nav drawer?

Offline twofast

  • Utente junior
  • **
  • Post: 60
  • Respect: 0
    • Mostra profilo
    • le mie app
  • Dispositivo Android:
    galaxy s3
  • Play Store ID:
    FastApp
Re:navigation drawer con activity
« Risposta #2 il: 22 Febbraio 2014, 17:52:52 CET »
0
calendario.xml
Codice (XML): [Seleziona]
<android.support.v4.widget.DrawerLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="match_parent"
   android:layout_height="match_parent">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >
    <CalendarView
       android:id="@+id/calendarView1"
       android:layout_width="352dp"
       android:layout_height="254dp"
       android:onClick=""
       android:importantForAccessibility="yes"
       android:showWeekNumber="false"
       android:scrollbars="horizontal"
       
        />
   
   
<TextView android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/contoallarovescia"
   android:text="Giorni mancanti"
   android:textSize="25sp"/>
<TextView android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:id="@+id/giorniassenze"
   android:text="assenze"
   android:textSize="25sp"/>

<TextView
   android:id="@+id/numeroassenze"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:text="Button" />

</LinearLayout>
</android.support.v4.widget.DrawerLayout>

intendi cosi? perché se è cosi non funziona...Non mi da errore ma se clicco in alto a sinistra non mi si apre il navigation drawer mentre nella pagina iniziale mi si apre

Offline twofast

  • Utente junior
  • **
  • Post: 60
  • Respect: 0
    • Mostra profilo
    • le mie app
  • Dispositivo Android:
    galaxy s3
  • Play Store ID:
    FastApp
Re:navigation drawer con activity
« Risposta #3 il: 02 Marzo 2014, 11:45:43 CET »
0
nessuno mi può aiutare?