Android-dev.it Community

 
Annunci

:arrow: Benvenuto!, se non sei ancora un utente registrato: puoi registrati qui, oppure effettua il login
:arrow: Apri un forum sul tuo nuovo smartphone Android e collabora con noi! (dettagli)

www.agendadigitale.org
Image


Sponsor
It is currently Tue May 22, 2012 9:51 am

All times are UTC + 1 hour


 Topics   Replies   Views   Last post 
No new posts На интернет-витрине

by popowahgjfghjoiuyt on Sat May 19, 2012 2:25 pm in Amministrazione

0

12

Sat May 19, 2012 2:25 pm

popowahgjfghjoiuyt

No new posts Apri un forum sul tuo nuovo smartphone Android!

[ Go to page: 1, 2, 3 ]

by ReattileGar on Fri May 18, 2012 5:27 pm in Amministrazione

27

12515

Fri May 18, 2012 5:27 pm

ReattileGar

No new posts Новый: базы для хрумера - профессиональный софт для СЕО.

by Renatafe on Fri May 18, 2012 3:14 pm in Amministrazione

0

17

Fri May 18, 2012 3:14 pm

Renatafe

No new posts Pace is undoubtedly the vital affordable Jerseys Wholesale d

by barnettmmolive2012 on Wed May 16, 2012 7:36 am in Amministrazione

1

47

Wed May 16, 2012 7:36 am

barnettmmolive2012

No new posts Problema di compatibilità app

by deran on Tue May 15, 2012 10:44 am in Sviluppo e programmazione in Android

4

200

Tue May 15, 2012 10:44 am

deran




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Evento su un oggetto checkable del submenu
PostPosted: Fri Apr 08, 2011 3:41 pm 
Offline
User avatar

Joined: Sat Feb 19, 2011 12:16 pm
Posts: 22
Punti Android: ?
Ho un menu con 6 voci che si apre premendo il tasto fisico Menu.
Alla pressione di una di queste voci esce un dialog composto da checkbox.
Alla scelta di ogni checkbox voglio associare un evento, ma no so come fare.

vi posto il codice del mio menu con relativo submenu:
Code:
@Override
        public boolean onCreateOptionsMenu(Menu menu) {
                super.onCreateOptionsMenu(menu);               
                Log.i(LOG_TAG, "onCreateOptionsMenu");
                int order = Menu.FIRST;

                int GROUPA = 0;
                menu.add(GROUPA, order, order++, "Voce1");
                menu.add(GROUPA, order, order++, "Voce2");
               
                int subGroupDi = 20;
                SubMenu subMenu1 = menu.addSubMenu(subGroupDi, order, order++, "Voce3");
                        subMenu1.add(subGroupDi, 0, 0, "Impostazione1");
                        subMenu1.add(subGroupDi, 0, 0, "Impostazione2");
                        subMenu1.add(subGroupDi, 0, 0, "Impostazione3");
                        subMenu1.setGroupCheckable(subGroupDi, true, false);
                       
                int subGroupId = 10;
                SubMenu subMenu2 = menu.addSubMenu(subGroupId, order, order++, "Voce4");
                        subMenu2.add(subGroupId, 0, 0, "Imp1");
                        subMenu2.add(subGroupId, 0, 0, "Imp2");
                        subMenu2.setGroupCheckable(subGroupId, true, true);

                menu.add(GROUPA, order, order++, "Voce5");
                menu.add(GROUPA, order, order++, "Voce6");

                return true;
        }


public boolean onOptionsItemSelected(MenuItem item, SubMenu subMenu1) {
                Log.i(LOG_TAG, "onOptionsItemSelected Called!");

                switch (item.getItemId()) {
                    case Menu.FIRST:
                        Log.i(LOG_TAG, "Voce1");
                        MiaActivity.this.miaBasic();
                        return true;
                       
                    case Menu.FIRST + 1:
                        Log.i(LOG_TAG, "Voce2");
                        return true;
                       
                    case Menu.FIRST + 2:
                        Log.i(LOG_TAG, "Voce3");
                        return true;                           
                               
                    case Menu.FIRST + 3:
                        Log.i(LOG_TAG, "Voce4");
                        return true;
                               
                    case Menu.FIRST + 4:
                        Log.i(LOG_TAG, "Voce5");
                        Intent intent1 = new Intent(this, CiaoActivity.class);
                        this.startActivity(intent1);           
                        return false;
                               
                    case Menu.FIRST + 5:
                        Log.i(LOG_TAG, "Voce6");
                        android.os.Process.killProcess(android.os.Process.myPid());
                        return true;
                    }
               
                Log.i(LOG_TAG, "onPrepareOptionsMenu " + item.getTitle());
                item.setChecked(!item.isChecked());
                return super.onOptionsItemSelected(item);
        }


Top
 Profile  
 
 Post subject: Re: Evento su un oggetto checkable del submenu
PostPosted: Sun Apr 10, 2011 7:19 am 
Offline
User avatar

Joined: Sat Feb 19, 2011 12:16 pm
Posts: 22
Punti Android: ?
è così difficile?
o mi sono espresso male?


Top
 Profile  
 
 Post subject: Re: Evento su un oggetto checkable del submenu
PostPosted: Sun Apr 10, 2011 3:42 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Ciao,
non vedo alcuna checkbox nel codice che hai postato... ma solo degli items che sono stati resi "checkable" tramite setGroupCheckable.
Quando l'utente seleziona una voce del submenu, la tua activity viene informata attraverso la chiamata al metodo di callback OnOptionsItemSelected(): è sufficiente implementare quel metodo per lanciare l'intent desiderato (usa il metodo getItemId() per identificare quale voce è stata premuta).


Top
 Profile  
 
 Post subject: Re: Evento su un oggetto checkable del submenu
PostPosted: Tue Apr 12, 2011 3:07 pm 
Offline
User avatar

Joined: Sat Feb 19, 2011 12:16 pm
Posts: 22
Punti Android: ?
grazie della risposta.
come puoi notare nell'onOptionsItemSelected ho gia settato alcuni eventi, ma
trovo difficoltà a impostare l'evento per gli items che ho reso "checkable".

se ho capito bene, ho modificato il metodo onOptionsItemSelected in questa maniera:
Code:
public boolean onOptionsItemSelected(MenuItem item) {
                Log.i(LOG_TAG, "onOptionsItemSelected Called!");

                switch (item.getItemId()) {
                    case Menu.FIRST:
                        Log.i(LOG_TAG, "Voce1");
                        MiaActivity.this.miaBasic();
                        return true;
                       
                    case Menu.FIRST + 1:
                        Log.i(LOG_TAG, "Voce2");
                        return true;
                       
                   case Menu.FIRST + 2:
             Log.i(LOG_TAG, "Voce3");
              return true;
             
               case Menu.FIRST + 3:
                  Log.i(LOG_TAG, "Voce3.1");
                  if (item.isChecked()) {
                     item.setChecked(false);
                  }else{
                     item.setChecked(true);
                  }
                   return true;   
             
               case Menu.FIRST + 4:
                  Log.i(LOG_TAG, "Voce3.2");
                  if (item.isChecked()) {
                     item.setChecked(false);
                  }else{
                     item.setChecked(true);
                  }
                   return true;         

               case Menu.FIRST + 5:
                  Log.i(LOG_TAG, "Voce3.3");
                  item.setChecked(true);
                    return true;             
            
          case Menu.FIRST + 6:
             Log.i(LOG_TAG, "Tipo Segnalazioni Selected");
            return true;
            
          case Menu.FIRST + 7:
             Log.i(LOG_TAG, "Tipo1");
              return true;
             
          case Menu.FIRST + 8:
             Log.i(LOG_TAG, "Tipo2");
              return true;
             
          case Menu.FIRST + 9:
             Log.i(LOG_TAG, "Tipo3");
              return true;
                               
                    case Menu.FIRST + 4:
                        Log.i(LOG_TAG, "Voce5");
                        Intent intent1 = new Intent(this, CiaoActivity.class);
                        this.startActivity(intent1);           
                        return false;
                               
                    case Menu.FIRST + 5:
                        Log.i(LOG_TAG, "Voce6");
                        android.os.Process.killProcess(android.os.Process.myPid());
                        return true;
                    }
               
                Log.i(LOG_TAG, "onPrepareOptionsMenu " + item.getTitle());
                item.setChecked(!item.isChecked());
                return super.onOptionsItemSelected(item);
        }

le tre checkbox fungono da filtri, per la gestione delle preferenze. nel senso che se seleziono la prima, allora eseguo A, se seleziono la prima e la seconda allora eseguo A e B.
come faccio a considerare tutti e due le checkbox? in questo caso?


Top
 Profile  
 
 Post subject: Re: Evento su un oggetto checkable del submenu
PostPosted: Sat Apr 23, 2011 6:15 pm 
Offline
Moderatore
User avatar

Joined: Thu Dec 27, 2007 3:51 pm
Posts: 986
Cellulare Android: HTC Dream
Operatore: TIM
Punti Android: 1320
Ivan86 wrote:
...le tre checkbox fungono da filtri, per la gestione delle preferenze. nel senso che se seleziono la prima, allora eseguo A, se seleziono la prima e la seconda allora eseguo A e B.
come faccio a considerare tutti e due le checkbox? in questo caso?

Scusa ma ho difficoltà a seguirti, se vuoi eseguire cose diverse in funzione di quali checkbox sono state selezionate, devi per forza lasciare la possibilità all'utente di selezionare/deselezionare le checkbox senza fare nulla e solo in un secondo momento, una volta effettuata la scelta, puoi processare la scelta dell'utente. Quindi devi per forza prevedere la pressione di un bottone: una volta premuto, fai il check di quali checkbox sono abilitate ed esegui quello che devi eseguire.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
phpBB SEO

All trademarks and logos used in this site are of properties of their respective owners.