×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    How to Compare AlertTypes

    HI frens,
    this is my code.

    ******************************************************
    //other necessary code

    private Alert customAlert;

    /**
    * CustomAlert constructor.
    */

    CustomAlert(String msg,AlertType type) {

    if(type==AlertType.ERROR)
    customAlert=new Alert("Exception",msg,Image.createImage("/icError.png"),AlertType.ERROR);
    else if(type.equals(AlertType.INFO)){
    customAlert=new Alert("Information",msg,Image.createImage("/icInfo.png"),AlertType.INFO);
    System.out.println("info");
    }
    else if(type.equals(AlertType.WARNING)){
    customAlert=new Alert("Warning",msg,Image.createImage("/icWarning.png"),AlertType.WARNING);
    }
    else{
    customAlert=new Alert("Other Alert",msg,Image.createImage("/icWarning.png"),AlertType.WARNING);
    }

    }

    ********************************************************

    but when i create object saying CustomAlert("error",AlertType.ERROR) none of the statements are executed.

    Can anyone tell how to check the type of alert.
    if AlertType.SOMETHING was an int i could have checked it , but
    AlertType.SOMETHING is of type AlertType itself .
    i can't use .equals also because its doing only '==' .
    I don't want to go for , say

    CustomAlert("message",1);
    or
    CustomAlert("message","error");

    pleaseeeeeeeee helpppppppp.

  2. #2
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to Compare AlertTypes

    Hi,

    I tried comparing AlertTypes with "==" and it worked. Then I tried your code (except for the images, I set those to null), and it didn't show anything. Excuse me for asking this silly question but did you set the display to customAlert?
    I just added
    Code:
    display.setCurrent(customAlert);
    as the last line in that code and all worked.

  3. #3
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Thumbs up Re: How to Compare AlertTypes

    Hi,
    try this:

    Code:
    		if (alertType.equalsIgnoreCase("info")) {
    			AlertT = AlertType.INFO;
    		} else if (alertType.equalsIgnoreCase("warning")) {
    			AlertT = AlertType.WARNING;
    		} else if (alertType.equalsIgnoreCase("error")) {
    			AlertT = AlertType.ERROR;
    		} else {
    			AlertT = AlertType.INFO;
    		}
    		alTest = new Alert("System Message", message, null, AlertT);

    Good Luck
    Y

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    13

    Re: How to Compare AlertTypes

    Thanks both of you for reply,

    Hi Bogdan Galiceanu,
    i've written display.setCurrent. but it didn't worked. can you just paste that code in reply if that worked.because i guess when im passing AlertType

    eg. CustomAlert ca=new CustomAlert("msg",AlertType.ERROR);

    so how do i compare while creating alert.
    because inside constructor

    public CustomAlert(String msg,AlertType type) {
    if(type==AlertType.ERROR){
    ///this doesn't work.im not even coming inside if statement.

    ********************************************************
    Now i tried this code
    //type is one which came as argument
    System.out.println("AlertType:arg"+type);
    //and this is the one which is given by the AlertType class
    System.out.println("AlertType:value"+AlertType.ERROR);
    i got output something like this.

    AlertType:argjavax.microedition.lcdui.AlertType@84aee8b
    AlertType:valuejavax.microedition.lcdui.AlertType@1cb37664

    this shows that both objects are having different hash values.
    so how one can compare.

    If you were successful then send me the code.
    or any other solution.
    don't say pass integer and check for that integer and create
    AlertType.ERROR for 1
    AlertType.INFO for something else.


    Thanks for your reply.
    Still need your help.


    Regard,
    Sandeep Gadhvi

  5. #5
    Regular Contributor
    Join Date
    Jun 2008
    Location
    Tel-Aviv,Israel
    Posts
    100

    Lightbulb Re: How to Compare AlertTypes

    Hi,
    Look at the my code example.
    Do not use "==". due to the fact that Strings are objects, not primitives.
    you can use:
    Code:
    private static final int error = 1;
    private static final int info  = 2;
    private static final int warning = 3;
    and then compare with the values.
    or use the previous code i have attached.

    Yaniv

  6. #6
    Nokia Developer Moderator
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: How to Compare AlertTypes

    Hi Sandeep,

    It seems I misunderstood what you meant. I thought you were using this as a method, not an object. Sorry about the confusion.

    As for the "==" used to compare AlertTypes, here is how I did it:
    Code:
    public void startApp() {
            a=AlertType.ALARM;
            b=AlertType.CONFIRMATION;
            c=AlertType.ALARM;
            display=Display.getDisplay(this);
            form=new Form("");
            if(a==b)
                form.append("a and b are equal");
            else
                form.append("a and b are different");
            if(a==c)
                form.append("a and c are equal");
            else
                form.append("a and c are different");
            display.setCurrent(form);
        }
    And the result was as expected: "a and b are different" and "a and c are equal".

Similar Threads

  1. How to compare date Sql Query in Symbian
    By kamaljaiswal in forum Symbian
    Replies: 2
    Last Post: 2009-08-31, 00:57
  2. compare descriptors
    By ismailc in forum Symbian
    Replies: 1
    Last Post: 2008-04-07, 19:43
  3. How to compare \n characters ?
    By HidayathKhan in forum Symbian
    Replies: 1
    Last Post: 2007-11-29, 08:57
  4. how to compare the contents of two buffers
    By Bhoopathi Kummara in forum Symbian
    Replies: 2
    Last Post: 2007-10-09, 11:08
  5. How can i compare HBufC string?
    By seera in forum Symbian
    Replies: 5
    Last Post: 2006-09-12, 09:13

Posting Permissions

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