×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Problem with CustomItem in Form

    Hi,

    I have a form with x number of items. Somewhere in between there is a CustomItem. My traverse method always retuns true and I have implemented my own code to jump in and out of the CustomItem. The code works fine until the CustomItem has gone completely out of view from the form (when CustomItem goes above what is visible) and I try to go back to the CustomItem.

    The form sets focus to wrong items and messes up completely. Why does it do this?


    Thanks,
    Ari

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi,
    Can you try this..
    Just remove the customItem form the FORM and check whether it works or not.
    Where you are appening this customItem in middle ,start or end..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi,
    Please check the link code,
    Its really helpful.
    http://developers.sun.com/mobility/m...ps/customitem/
    Hope this helps you in any means,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Problem with CustomItem in Form

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Can you try this..
    Just remove the customItem form the FORM and check whether it works or not.
    Where you are appening this customItem in middle ,start or end..
    Thanks,
    Thanks for the reply.

    The form works perfectly without the CustomItem of course. If I append the the CustomItem at the and of the form there will be no errors because I can't get the CustomItem out of view. I hope you got my point: the error ONLY occurs when the CustomItem has gone above what is visible in the form AND I try to go back to the item by going up.

    Example:
    Form with items:
    CustomItem1
    Item1
    Item2
    Item3

    When I've done what I wanted in CustomItem1 and I go to Item3 and I can no longer see CustomItem1 on the screen. Now if I go back to CustomItem1, it will be buggy. NOTE: There is nothing wrong if I even go to Item2 and if I can still see the CustomItem1 on the screen and I want to go back to CustomItem1. Why is this? Haven't figured this out yet...

    --
    Ari

  5. #5
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Problem with CustomItem in Form

    Hi Ari,

    this sounds like some issue in your traverse() implementation. Try debugging that code and, if it still does not work, try posting it here so It'll be possible to help you with it.

    Pit

    PS: where are you testing your code? Which device/emulator?

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi Ari,
    Having the idea of your problem, I gave the underlined link that includes the same demo what you are doing now and looking for.
    As stated by pit check the code what you have done..check also that demo.
    It really helpful,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Problem with CustomItem in Form

    Quote Originally Posted by raj_J2ME View Post
    Hi Ari,
    Having the idea of your problem, I gave the underlined link that includes the same demo what you are doing now and looking for.
    As stated by pit check the code what you have done..check also that demo.
    It really helpful,
    Thanks,
    I checked the demo, but it didn't even use traverse to jump around. Even with that demo and my traverse, it would work fine. It's only when I can no longer see the CustomItem in the form and then I come back to it from the bottom of the form. If I come up to down on the form to the CutomItem, there is no problem with this.

    Here is some code for you (up and down cases):
    case Canvas.DOWN:
    if(entered==true)Survey.setFocusToItem(location+1);
    if(!entered)entered = true;
    else if(entered)entered = false;
    repaint();
    break;
    case Canvas.UP:
    if(entered==true){
    if(location > 0)
    Survey.setFocusToItem(location-1);
    }
    if(!entered)entered = true;
    else if(entered)entered = false;
    repaint();
    break;
    }

    location is an int that knows the location of the CustomItem in the form. entered is boolean that knows whether the user has entered the CustomItem or not.

    For some reason the traverse method is not even called when I move out of the CustomItem when I move from bottom to up in the Form.

    Thanks,
    Ari
    Last edited by arinu; 2008-11-12 at 10:36.

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Problem with CustomItem in Form

    Quote Originally Posted by jappit View Post
    Hi Ari,

    this sounds like some issue in your traverse() implementation. Try debugging that code and, if it still does not work, try posting it here so It'll be possible to help you with it.

    Pit

    PS: where are you testing your code? Which device/emulator?
    That's what I would think too, but there is nothing wrong with the traverse if the CustomItem hasn't gone above what is visible on the screen AND I've come back to the CustomItem.

    I'm using S60 3rd Edition FP2 SDK for MIDP device on E90 (working with Eclipse). The same bug occurs with the emulator as well.

    Thanks,
    Ari
    Last edited by arinu; 2008-11-12 at 10:23.

  9. #9
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi,
    For the testing purposes you keep on adding the item as in you application to the demo then check..what happens
    Thats all I can tell you without going through the compete code..

    If it is happening on the emulator too then I must say there is any issue with your code.
    Please put the system.out.println() inside and check the value of current selection and selected item on the up and down key pressed .
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  10. #10
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Problem with CustomItem in Form

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    For the testing purposes you keep on adding the item as in you application to the demo then check..what happens
    Thats all I can tell you without going through the compete code..

    If it is happening on the emulator too then I must say there is any issue with your code.
    Please put the system.out.println() inside and check the value of current selection and selected item on the up and down key pressed .
    Thanks,
    I created a small program for you. Test this and tell me if you get the same bugs? Go to the bottom of the form and come back up. Notice how traverse() is called only once when you go completely from the bottom to top? If I move so that the Slider is still visible and move to the top, traverse() is called twice.

    There are 2 classes in package main: TestForm and SliderItem.

    package main;

    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    import javax.microedition.lcdui.Form;
    import javax.microedition.lcdui.TextField;
    import javax.microedition.lcdui.Display;

    public class TestForm extends MIDlet {
    private static Form form;
    private TextField si1;
    private TextField si2;
    private TextField si3;
    private TextField si4;
    private TextField si5;
    private TextField si6;
    private SliderItem slider;

    private static Display display;

    public TestForm() {
    form = new Form("TestForm");
    si1 = new TextField("TextField", "No content", 100, 0);
    si2 = new TextField("TextField", "No content", 100, 0);
    si3 = new TextField("TextField", "No content", 100, 0);
    slider = new SliderItem("Label", 0, 10, "bad", "good", 1);
    si4 = new TextField("TextField", "No content", 100, 0);
    si5 = new TextField("TextField", "No content", 100, 0);
    si6 = new TextField("TextField", "No content", 100, 0);
    }

    protected void destroyApp(boolean arg0) throws MIDletStateChangeException {}

    protected void pauseApp() {}

    protected void startApp() throws MIDletStateChangeException {
    if (display == null) display =
    Display.getDisplay(this);
    form.append(si1);
    form.append(slider);
    form.append(si2);
    form.append(si3);
    form.append(si4);
    form.append(si5);
    form.append(si6);
    display.setCurrent(form);
    }

    public static void setFocusToItem(int value){
    display.setCurrentItem(form.get(value));
    display.setCurrent(form);
    }

    }




    And slider:

    package main;


    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.CustomItem;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;


    public class SliderItem extends CustomItem
    {
    protected static final int TRAVERSE_HORIZONTAL = 1;
    protected static final int TRAVERSE_VERTICAL = 2;
    private int min, max;
    private String minLabel, maxLabel;
    // private Display display;
    private int width = 0, height = 0;
    private int contentWidth, contentHeight;
    private int sliderWidth;
    private int sliderAreas;
    private int sliderAreaWidth;
    private int sliderStart;
    private Font fn;
    private Font fn2;
    private boolean moved;
    private boolean entered;
    private int index;
    private boolean traverse;
    private int location;

    private final int MARGIN_X = 3;
    private final int MARGIN_Y = 11;
    private final int SLIDER_HEIGHT = 10;
    private final int LABEL_Y = 30;

    public SliderItem(String label)
    {
    super(label);
    min = 0;
    max = 1;
    minLabel = "";
    maxLabel = "";
    moved = false;
    fn = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    fn2 = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    countSliderSize();
    index = 0;

    }

    public SliderItem(String label, int nMin, int nMax, String nMinLabel, String nMaxLabel, int nLocation) {
    super(label);
    min = nMin;
    max = nMax;
    minLabel = nMinLabel;
    maxLabel = nMaxLabel;
    moved = false;
    fn = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    fn2 = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    countSliderSize();
    index = 0;
    location = nLocation;
    }

    public void setMin(int nMin) {
    min = nMin;
    }

    public int getMin() {
    return min;
    }

    public void setMax(int nMax) {
    max = nMax;
    }

    public int getMax() {
    return max;
    }

    protected void paint( Graphics g, int p2, int p3 )
    {
    // slider
    g.drawRect(sliderStart, MARGIN_Y, sliderWidth, SLIDER_HEIGHT);
    // slider area
    for (int i = 1; i < sliderAreas; i++) {
    int x = i * sliderAreaWidth + sliderStart;
    //System.out.println("x is: " + x);
    g.drawLine(x, MARGIN_Y, x, MARGIN_Y + SLIDER_HEIGHT);
    }
    // chosen slider, only if just entered or moved
    if (entered == true | moved == true) {
    int x = index * sliderAreaWidth + sliderStart;
    if (entered == true) { g.setColor(255, 0, 0); } else { g.setColor(0, 0, 0); }
    g.fillRect(x, MARGIN_Y, sliderAreaWidth, SLIDER_HEIGHT);
    g.setColor(0, 0, 0);
    }
    // min and max
    g.setFont(fn);
    g.drawString(Integer.toString(min), MARGIN_X, 3, Graphics.LEFT | Graphics.TOP);
    g.drawString(Integer.toString(max), contentWidth - MARGIN_X, 3, Graphics.RIGHT | Graphics.TOP);
    // min ja max labels
    g.setFont(fn2);
    g.drawString(minLabel, MARGIN_X, LABEL_Y, Graphics.LEFT | Graphics.TOP);
    g.drawString(maxLabel, contentWidth - MARGIN_X, LABEL_Y, Graphics.RIGHT | Graphics.TOP);
    }

    public void countSliderSize() {
    sliderAreas = max - min + 1;
    int maxWidth = contentWidth - (2 * MARGIN_X) - 10 - (fn.stringWidth(Integer.toString(min) + fn.stringWidth(Integer.toString(max))));
    sliderAreaWidth = (maxWidth / sliderAreas);
    sliderWidth = sliderAreaWidth * sliderAreas;
    sliderStart = fn.stringWidth(Integer.toString(min)) + 5;
    }

    protected void sizeChanged(int w, int h) {
    contentWidth = w;
    contentHeight = h;
    countSliderSize();
    repaint();
    }

    //white box that sometimes appears
    protected int getMinContentHeight( )
    {
    return 50;
    }

    protected int getMinContentWidth( )
    {
    return 215;
    }

    public void setMySize(int w, int h){
    width = w;
    height = h;
    }

    protected int getPrefContentHeight( int p1 )
    {
    return height;
    }

    protected int getPrefContentWidth( int p1 )
    {
    return width;
    }


    protected boolean traverse(int dir, int viewportWidth, int viewportHeight,
    int[] visRect_inout) {
    traverse = true;
    if (moved == false) {
    index = sliderAreas / 2;
    }

    switch (dir) {
    case Canvas.LEFT:
    //System.out.println("left");
    if ((index + min) > min) {
    index--;
    moved = true;
    }
    if(!entered)entered = true;
    repaint();
    break;
    case Canvas.RIGHT:
    //System.out.println("right");
    if ((index + min) < max) {
    index++;
    moved = true;
    }
    if(!entered)entered = true;
    repaint();
    break;
    case Canvas.DOWN:
    if(entered==true)TestForm.setFocusToItem(location+1);
    if(!entered)entered = true;
    else if(entered)entered = false;
    repaint();
    break;
    case Canvas.UP:
    System.out.println("up");
    if(entered==true){
    if(location > 0)
    TestForm.setFocusToItem(location-1);
    }
    if(!entered)entered = true;
    else if(entered)entered = false;
    repaint();
    break;
    }
    return traverse;
    }

    //this method is called when traverse returns false (never)
    protected void traverseOut() {
    entered = false;
    repaint();
    }


    }


    Thanks,
    Ari
    Last edited by arinu; 2008-11-12 at 11:29.

  11. #11
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi,
    Yeah I made it and find the perfect source code here..
    it is having the 6 text field and the custom item in between.You put the custom item where you want and it will work like perfect.
    tell me shall I put the code here or, mail to you..
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  12. #12
    Registered User
    Join Date
    Jun 2008
    Posts
    19

    Re: Problem with CustomItem in Form

    Quote Originally Posted by raj_J2ME View Post
    Hi,
    Yeah I made it and find the perfect source code here..
    it is having the 6 text field and the custom item in between.You put the custom item where you want and it will work like perfect.
    tell me shall I put the code here or, mail to you..
    Thanks,
    You can put it here.

    Hope it works,
    Ari

  13. #13
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Problem with CustomItem in Form

    Hi,
    This the demo I have upgrade..
    this is the first file-

    import javax.microedition.lcdui.*;

    // A minimal implementation of a MIDP 2.0
    // custom item. Fills its content area with
    // a white rectangle.

    public class MinimalItem extends CustomItem
    {
    public MinimalItem( String label )
    {
    super( label );
    }

    // Returns the minimal height of the content
    // area.

    protected int getMinContentHeight()
    {
    return 40;
    }

    // Returns the minimal width of the content
    // area.

    protected int getMinContentWidth()
    {
    return 40;
    }

    // Returns the preferred height of the content
    // area. A tentative value for the opposite
    // dimension -- the width -- is passed to aid
    // in the height calculation. The tentative value
    // should be ignored if it is -1.

    protected int getPrefContentHeight( int width )
    {
    return getMinContentHeight();
    }

    // Returns the preferred width of the content
    // area. A tentative value for the opposite
    // dimension -- the height -- is passed to aid
    // in the width calculation. The tentative value
    // should be ignored if it is -1.

    protected int getPrefContentWidth( int height )
    {
    return getMinContentWidth();
    }

    // Draws the item's content area, whose dimensions
    // are given by the width and height parameters.

    protected void paint( Graphics g, int width, int height )
    {
    g.setColor( 255, 255, 255 );
    g.fillRect( 0, 0, width, height );
    }
    }

    and this is second-
    /*
    * MinimalItemTest.java
    *
    * Created on November 12, 2008, 2:38 PM
    */

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;

    /**
    *
    * @author rajiv
    * @version
    */
    public class MinimalItemTest extends MIDlet implements CommandListener
    {
    private Display display;
    public static final Command exitCommand =
    new Command( "Exit",
    Command.EXIT, 1 );
    private TextField si1;
    private TextField si2;
    private TextField si3;
    private TextField si4;
    private TextField si5;
    private TextField si6;

    public MinimalItemTest()
    {
    }

    public void commandAction( Command c,
    Displayable d )
    {
    if( c == exitCommand )
    {
    exitMIDlet();
    }
    }

    protected void destroyApp( boolean unconditional )
    throws MIDletStateChangeException
    {
    exitMIDlet();
    }

    public void exitMIDlet()
    {
    notifyDestroyed();
    }

    public Display getDisplay()
    { return display; }

    protected void initMIDlet()
    {
    // Create a custom item and set its layout
    // policy.

    MinimalItem mi = new MinimalItem( "label -1" );
    mi.setLayout( Item.LAYOUT_CENTER |
    Item.LAYOUT_NEWLINE_BEFORE |
    Item.LAYOUT_NEWLINE_AFTER );
    MinimalItem mii = new MinimalItem( "label -2" );
    mi.setLayout( Item.LAYOUT_CENTER |
    Item.LAYOUT_NEWLINE_BEFORE |
    Item.LAYOUT_NEWLINE_AFTER );

    Form f = new Form( "MinimalItem Test" );
    si1 = new TextField("TextField", "No content", 100, 0);
    si2 = new TextField("TextField", "No content", 100, 0);
    si3 = new TextField("TextField", "No content", 100, 0);
    si4 = new TextField("TextField", "No content", 100, 0);
    si5 = new TextField("TextField", "No content", 100, 0);
    si6 = new TextField("TextField", "No content", 100, 0);

    //f.append( "Before..." );
    //f.append( mi );
    //f.append( "... and after" );

    f.append(si1);
    f.append(si2);
    f.append( mi );
    f.append(si3);
    f.append(si4);
    f.append(si5);
    f.append(si6);
    f.append( mii );
    f.addCommand( exitCommand );
    f.setCommandListener( this );

    getDisplay().setCurrent( f );
    }

    protected void pauseApp()
    {
    }

    protected void startApp()
    throws MIDletStateChangeException
    {
    if( display == null )
    {
    display = Display.getDisplay( this );
    initMIDlet();
    }
    }
    }


    I hope this was the requirement..
    I believe that this can help you,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  14. #14
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Problem with CustomItem in Form

    hadn't the time to check all of ur code just saw this passing by :

    case Canvas.UP:
    if(entered==true){
    if(location > 0)
    Survey.setFocusToItem(location-1);
    }
    if(!entered)entered = true;
    else if(entered)entered = false;
    repaint();
    break;
    }

    maybe u should use something as

    Survey.setFocusToItem(location%numberOfItems-1);


    ???

  15. #15
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Problem with CustomItem in Form

    Hi arinu,

    try changing your Canvas.UP and Canvas.DOWN cases in the switch statement as follows:
    Code:
    case Canvas.DOWN:
    case Canvas.UP:
    	entered = !entered;
    	return entered;
    As a side note: when posting code, enclose it into 'code' tags, so it'll be easier to read.

    Pit

Similar Threads

  1. Midlet form focus problem
    By x-it in forum Mobile Java General
    Replies: 6
    Last Post: 2009-11-16, 12:36
  2. CustomItem traversal on MIDP Form - bug?
    By mbetan in forum Mobile Java General
    Replies: 8
    Last Post: 2008-12-02, 17:43
  3. Problem MMC+USB Connection
    By Fede81 in forum Symbian
    Replies: 1
    Last Post: 2007-06-14, 06:13
  4. Problem posting XHTML form
    By renditor in forum Browsing and Mark-ups
    Replies: 2
    Last Post: 2005-12-03, 03:58
  5. Problem in Displaying the Form
    By pratbrat77 in forum Symbian
    Replies: 0
    Last Post: 2003-12-10, 21:09

Posting Permissions

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