×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    270

    How to store previously selected value of popupchoice menu

    I am working on s40 app and used popupchoicegroup .
    My scenario is as follows. I made action listeners on one button(stng) which openes me a "setting" form. I made popupchoicegroup in this form and applied action listeners for popupchoicegroup inside action listeners of button stng.
    For saving state of previously selected option i am using group.setselected(index); but my changes are not getting saved when i click "stng" button again(not getting previous value of font selected). Here is my code........

    Code:
    int index=0;   // i declared this globally
    RadioButton [] choices; //declared globally
    PopupChoiceGroup group2;  //declared globally
    stng.addActionListener(new ActionListener() {                          //ACTION LISTENER FOR BUTTON  
    	
    	public void actionPerformed(ActionEvent arg0) {
    	
    		// TODO Auto-generated method stub
    		System.out.println("IN SETTINGS FORM");             //declared a form too 
    
    	 choices2 = new RadioButton[3];
    		  choices2[0] = new RadioButton("Tahoma");
    		  choices2[0].addActionListener(new ActionListener() {           ACTION LISTENER FOR FONT
    		  public void actionPerformed(ActionEvent arg0) {
    			  try {
    				r = Resources.open("/myfont.res");
    				Font myfont=r.getFont("Font1");
    				thoughtext.getUnselectedStyle().setFont(myfont);
    				thoughtext.repaint();
    				index=0;
                                   group2.setSelected(index);
    				System.out.println("VALUE OF INDEX IN TAHOMA IS"+index);
    				first.show();
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    			
    			}
    		});
    		    choices2[1] = new RadioButton("Comic Sans MS");           //ACTION LISTENER FOR FONT
    		    choices2[1].addActionListener(new ActionListener() {
    				  public void actionPerformed(ActionEvent arg0) {
    					  try {
    						r = Resources.open("/mycomic1.res");
    						Font myfont=r.getFont("mjcomic");
    						thoughtext.getUnselectedStyle().setFont(myfont);
    						thoughtext.repaint();
    						index=1;
                                                   group2.setSelected(index);
    						System.out.println("VALUE OF INDEX IN COMIC IS"+index);
    						first.show();
    					} catch (IOException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    					
    					}
    				});
    		    choices2[2] = new RadioButton("Serif");
    		    choices2[2].addActionListener(new ActionListener() {             //ACTION LISTENER FOR FONT
    				  public void actionPerformed(ActionEvent arg0) {
    					  try {
    						r = Resources.open("/seriffont.res");
    						Font myfont=r.getFont("serifdb");
    						thoughtext.getUnselectedStyle().setFont(myfont);
    						thoughtext.repaint();
    						index=2;
                                                     group2.setSelected(index);
    						System.out.println("VALUE OF INDEX IN SERI IS"+index);
    						first.show();
    					} catch (IOException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    					
    					}
    				});
    	
    		    
    		 group2 = new PopupChoiceGroup("Text Style", choices2);
    		System.out.println("VALUE OF INDEX BEFORE IS"+index);         
    		group2.setSelected(index);
    		System.out.println("VALUE OF INDEX AFTER IS"+index);
    
    
     stngform.addComponent(group2);
     
    		stngform.show();
    	}
    });
    How to solve this issue
    Last edited by Manpreet_Singh; 2013-08-27 at 07:09. Reason: code

  2. #2
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to store previously selected value of popupchoice menu

    ok... trying this

  3. #3
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to store previously selected value of popupchoice menu

    Instead of using index at both places, use index and index1 to identify the selected index at 2 levels.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  4. #4
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to store previously selected value of popupchoice menu

    sir how to use it in code ,,,i tried .. even if i take two variables then value of variable in action listener of font is not reflected out of that block(though i took it globally).

  5. #5
    Registered User
    Join Date
    Dec 2012
    Location
    India
    Posts
    264

    Re: How to store previously selected value of popupchoice menu

    Hi

    The underlying actionListener code for each radio button was not executed when I tried to work with PopupChoicegroup. Secondly, by default , the first item is selected in a PopupChoiceGroup, which will have an index of 0.In the code posted by you,you are setting the index as 0 again in the begining .Hence there wont appear to be any change at all.Set it to something else, I am sure it will work.

    I tried using the setIndex() and getIndex() with various values, and I was able to change the index properly and also the selected item remained the same even after going back and forth various forms.I am not sure why you got any problems.

    Neverthless,I would like to add that each time the settings button is clicked, the popupChoicegroup is getting created again.This is a waste of processing since I believe your settingsForm is global.

    You could rewrite your code like this :

    Code:
               if (stngform == null) {
                        stngform = new Form("Settings");
    
                        choices2 = new RadioButton[3];
                        choices2[0] = new RadioButton("Tahoma");
                         .... // rest of the code
                     }
                    stngform.show();
    This way the form and its components wont get created again and again and may likely solve your issue!
    Last edited by arunkam; 2013-08-27 at 16:25.

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: How to store previously selected value of popupchoice menu

    Quote Originally Posted by Manpreet_Singh View Post
    sir how to use it in code ,,,i tried .. even if i take two variables then value of variable in action listener of font is not reflected out of that block(though i took it globally).
    Please cleanup your code as Arun Suggested, don't recreate the choice group everytime and use setter and getter's to set and get the value of index's at various levels - setting them in different variables like IndexL1 and IndexL2. Make these variables Public Static Int - so that only single instance of these are created at a time.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  7. #7
    Registered User
    Join Date
    May 2013
    Posts
    270

    Re: How to store previously selected value of popupchoice menu

    thanks for help.

Similar Threads

  1. Replies: 1
    Last Post: 2009-07-04, 14:22
  2. How to set a cursor to selected menu item previously?
    By whasj35 in forum Symbian User Interface
    Replies: 4
    Last Post: 2009-06-23, 11:47
  3. Replies: 1
    Last Post: 2008-12-22, 18:10
  4. Initial menu when app selected?
    By fsiegel in forum Symbian User Interface
    Replies: 5
    Last Post: 2004-10-14, 22:28
  5. how do i store the selected items in a multi select list?
    By advocatee in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-09-15, 18:41

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •