×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    37

    loose focus of textfield

    Hi,

    I developed a little quizz where the user has to input the answer (only one word) in a textfield. Therefore I use a Form. If the answer is entered an "check" pressed, I check the input, delete the textfield and insert a StringItem to display the result. In Sun'S WTK 2.1 everything was fine but in Noka S60 SKD Beta 1.3 after the first word I loose the focus of the textfield. The cursor is still blinking but I can't enter a single letter.

    Do you think it is a problem to add and remove Items? Will this flicker on a real device? Would you recommand to use two different forms for question and answer?

    Perhaps there is only a problem in my code?

    I added some parts below.

    Many thanks for advices.

    Heike

    Code:
        
        /**
         * constructor
         */
        public UebForm() {
            
    (...)
            si_frage = new StringItem(null, ""); // for question
            si_frage.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM));
    //        si_frage.setLayout(Item.LAYOUT_NEWLINE_AFTER);
            
            tf_antwort = new TextField(null, "", 30, TextField.ANY);
    // for answer
            
            si_loesung = new StringItem(null, ""); // for result
            si_loesung.setFont(Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM));
    //        si_loesung.setLayout(Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_NEWLINE_BEFORE);
            
            space = new Spacer(getWidth(),1);
            space2 = new Spacer(getWidth(), 1);
            try {
                s0 = Image.createImage("/layout/s0.png");  
            } catch(Exception e){System.out.println("s0 nicht geladen");}
            try {
                s1 = Image.createImage("/layout/s1.png");  
            } catch(Exception e){System.out.println("s1 nicht geladen");} // images for displaying progress
    
            append(si_frage);
            append(space);
            append(tf_antwort);
            append(space2);
            ar_ii_stern = new ImageItem[numUeb];
            for(int i=0; i<numUeb; i++){
                ar_ii_stern[i] = new ImageItem(null, s0, ImageItem.LAYOUT_LEFT, null);
                append(ar_ii_stern[i]);
                System.out.println(ar_ii_stern[i]);
            }
    //        ar_ii_stern[0].setLayout(Item.LAYOUT_NEWLINE_BEFORE);
            progItem = new ProgressItem(); // a progressbar
            append(progItem);
            progItem.setLayout(Item.LAYOUT_NEWLINE_BEFORE);
            
            try {
                // Set up this form to listen to command events
                setCommandListener(this);
                addCommand(CMD_CHECK);
                addCommand(CMD_BACK);
                addCommand(CMD_Choose);
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        
        // getting data from other form
        public void initForm(Displayable dis, Vector data, int call, int _anz){
            vec_data = data;
            System.out.println("daten in UebCan:"+vec_data);
            numUeb = LelaVoc.numUeb;
            parent = dis;
            caller = call;
            anz = vec_data.size();
            counter = 0;
            anzGes = _anz; // number of all tasks
            
            voc=(Voc)vec_data.elementAt(counter);
            si_frage.setText(voc.getDeutsch()); // voc = value Object for keeping data of tasks
    
             ustatDE = voc.getUstatDE();
             if(ustatDE==0){
                for(int i=0; i<ar_ii_stern.length; i++){
                     ar_ii_stern[i].setImage(s0);
                }
            }else{
                for(int i=0; i<ar_ii_stern.length; i++){
                    if(i<ustatDE){
                        ar_ii_stern[i].setImage(s1);
                    }
                    else{
                        ar_ii_stern[i].setImage(s0); 
                    }
                }
             }
             progItem.setProgress(anzGes, anz);
             System.out.println ("Progress set");
                lektion = voc.getLektion();
                ID = voc.getID();
                rms=voc.getLektion();
                vocDB.openRMS(rms); 
        }
        
        
        private void reset(){
            t=0;
        }
        
        
         /**
         * build page for asking the question
         */
        public void display(){
            voc=(Voc)vec_data.elementAt(counter);
    
                    si_frage.setText(voc.getDeutsch());
                    si_frage.setLayout(Item.LAYOUT_LEFT);
                    ustatDE = voc.getUstatDE();
                    if(ustatDE==0){
                        for(int i=0; i<ar_ii_stern.length; i++){
                            ar_ii_stern[i].setImage(s0);
                        }
                    }else{
                        for(int i=0; i<ar_ii_stern.length; i++){
                            if(i<ustatDE){
                                ar_ii_stern[i].setImage(s1);
                            }
                            else{
                                ar_ii_stern[i].setImage(s0); 
                            }
                        }
                    }
                    display.setCurrent(this);
    
        }
        
        /**
         * checks answer (always one word required -> sometimes parsing necessary -> until the first empt space
         */
        private void check(){
            boolean check = false;
            String input = tf_antwort.getString().trim();
            String antwort = voc.getEnglisch();
            
            if(input.equals(antwort)){
                check = true;            
            }
            else{
                
                char[] ch = antwort.toCharArray();
                int i = 0;
                int k = 0;
                while(i < ch.length){
                    if(ch[i] == ' '){
                        if(antwort.substring(k, i).trim().equals(input)){
                            check = true;
                        }
                        k = i+1;
                    }
                i++;
                }
            }
            
            if(check){
                si_frage.setText("Richtig!");  
                if(rms!= lektion){
                    vocDB.close();
                    if(vocDB.openRMS(lektion)){
                        rms = voc.getLektion();
                    }
                }
                    ustatDE = voc.getUstatDE();
                    ustatDE++;
                    voc.setUstatDE(ustatDE);
                    if(ustatDE == numUeb){
                        vec_data.removeElementAt(vec_data.indexOf(voc));
                    }
                    else{
                        counter++;
                    }
                
                
                vocDB.saveStatus(voc);
            }
            else{
                si_frage.setText("Leider nicht. Hier die korrekte Übersetzung:");
                counter++;
            }
    //        si_frage.setLayout(Item.LAYOUT_CENTER);
    //        si_frage.setLayout(Item.LAYOUT_CENTER | Item.LAYOUT_NEWLINE_AFTER);
            tf_antwort.delete(0,tf_antwort.size());
            if(ustatDE==0){
                for(int i=0; i<ar_ii_stern.length; i++){
                     ar_ii_stern[i].setImage(s0);
                }
            }else{
                for(int i=0; i<ar_ii_stern.length; i++){
                    if(i<ustatDE){
                        ar_ii_stern[i].setImage(s1);
                    }
                    else{
                        ar_ii_stern[i].setImage(s0); 
                    }
                }
             }
               
           
            
        }
        
        /**
         * Called when user action should be handled
         */
        public void commandAction(Command c, Displayable d) {
         (...)
            else if(c==CMD_CHECK){
                check();
                reset();
                // displaying result page
                 delete(4);
    //            append(si_loesung);
                 insert(4, si_loesung);     
                
                si_loesung.setText(voc.getDeutsch()+":\n"+voc.getEnglisch());
    //            si_loesung.setLayout(Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_NEWLINE_AFTER);
                removeCommand(CMD_CHECK);
                addCommand(CMD_GO);
                addCommand(CMD_TON);
                progItem.setProgress(anzGes, vec_data.size());
                display.setCurrent(this);
                 
            }
            else if(c==CMD_GO){
                if(vec_data.size() > 0){
                    if(counter == vec_data.size()){
                        counter = 0;
                        roundCount++;
                        }
                    }
                    // displaying answer page
                    delete(4);
    //            append(tf_antwort);
                    insert(4, tf_antwort);
                    removeCommand(CMD_GO);
                    removeCommand(CMD_TON);
                    addCommand(CMD_CHECK);
                    display();
                    lektion = voc.getLektion();
                    ID = voc.getID();
                }else{
                    AlertForm.instance.setInfo(done, parent, 1);
                    display.setCurrent(AlertForm.instance);
                    mainmenu.setCurr(AlertForm.instance);
                    vec_data=null;
                }
                
            }
            
        }

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    37
    ...must have been a problem of sdk, I installed S60_sdk_2.1_beta, now it works in the emulator.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    6
    I cant get the 2.1 beta to work with the networking... possible a configuration problem...
    (2.1 beta is windows only as well ).

Posting Permissions

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