BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 05-07-2007, 08:03 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default image in ListField

Please Login to Remove!

Hi,
i want to have a little image before each item in the ListField. I tried this one here:
Code:
import net.rim.device.api.ui.Graphics;
/*...*/
private static final Bitmap myIcon = Bitmap.getBitmapResource("icon.gif");
/*...*/
String fieldOne = new String("Zeile 1");
        String fieldTwo = new String("Zeile 2");
        ListField myList = new ListField();
        ListCallback myCallback = new ListCallback();
        myList.setCallback(myCallback);
        myList.insert(0);
        myList.insert(1);
        myList.insert(2);
        myCallback.insert(fieldOne,0);
        myCallback.insert(fieldTwo,1);
        myCallback.insert(fieldOne,2);
        add(myList);
/*...*/
private static class ListCallback implements ListFieldCallback {
        private Vector listElements = new Vector();
        public void drawListRow(ListField list, Graphics g, int index, int y,int w) {
            Graphics tmp = new Graphics(myIcon);
            //img.
            String text = (String)listElements.elementAt(index);
                      
            Image source; // the image to be copied
            source = Image.createImage(myIcon);
            g.drawImage(source,0,y,0);
            g.drawText(text,15,y,0,w);           
        }
But the compiler don't like the two rows
Code:
Image source; // the image to be copied
source = Image.createImage(myIcon);
if i use the var tmp then the compiler don't like this row:
Code:
g.drawImage(tmp,0,y,0);
Quote:
cannot find symbol
symbol : method drawImage(net.rim.device.api.ui.Graphics,int,int,i nt)
location: class net.rim.device.api.ui.Graphics
so how can i put this little image before the text of an item?

hibbert

Last edited by hibbert : 05-07-2007 at 08:04 AM. Reason: wrong BBcode
Offline  
Old 05-07-2007, 09:53 PM   #2 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8800
PIN: N/A
Carrier: n/a
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

There are two Graphics classes in J2ME/RIM libraries:

* the one you're using from RIM
* the "original" class from J2ME SDK: javax.microedition.lcdui.Graphics

Looks like you looked up drawImage() prototype for the latter one and actually tried to use the former. Use the RIM class and it should resolve your issues.
Offline  
Old 05-08-2007, 02:54 AM   #3 (permalink)
New Member
 
Join Date: Apr 2007
Model: 7100T
Carrier: airtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default splash image

Can anyone out here please help me out in resolving my image problem.
i'm not able to code for the splash scrren.please help mem out with the complete source code of the splash screen java class.i'm really in trouble ands highly confused.i'm a beginner.
please anyone out here help me out
Offline  
Old 05-08-2007, 03:48 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by PeterK View Post
There are two Graphics classes in J2ME/RIM libraries:

* the one you're using from RIM
* the "original" class from J2ME SDK: javax.microedition.lcdui.Graphics

Looks like you looked up drawImage() prototype for the latter one and actually tried to use the former. Use the RIM class and it should resolve your issues.
How do i use the RIM class?
I see I'm using two different image-types, but how can i convert my image into the right one?

hibbert
Offline  
Old 05-08-2007, 05:24 AM   #5 (permalink)
CrackBerry Addict
 
Join Date: Jun 2005
Location: Manchester, UK
Model: BOLD
Carrier: t-mobile
Posts: 714
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

just add a .png to your project, create the image in the class constructor using:

Bitmap mybitmap = Bitmap.getBitmapResource("myimage.png");

then in your drawlistrow method use something like:

graphics.drawBitmap(0, y, 18, rowHeight, mybitmap, 0, 0);
__________________
new job doesn't allow a public profile - please do not contact this user with questions, you will not get a response. good luck!
Offline  
Old 05-08-2007, 08:50 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok, i tried this one here:
Code:
      private static class ListCallback implements ListFieldCallback {
        private Vector listElements = new Vector();
        public void drawListRow(ListField list, Graphics g, int index, int y,int w) {
            Graphics tmp = new Graphics(myIcon);
            Bitmap mybitmaP = Bitmap.getBitmapResource("icon.gif");
            String text = (String)listElements.elementAt(index);
            //Image source; // the image to be copied
            //source = Image.createImage(myIcon);
            //g.drawImage(source,0,y,0);
            //g.drawImage(tmp,0,y,0);
            g.drawImage(mybitmaP,0,0,0);
            g.drawText(text,15,y,0,w);
        }
But my lovely compiler said:
Quote:
cannot find symbol
symbol : method drawImage(net.rim.device.api.system.Bitmap,int,int ,int)
location: class net.rim.device.api.ui.Graphics
g.drawImage(mybitmaP,0,0,0);
so I think I have to change mybitmaP into a Graphic (Typ Graphics) or so...

how do I change the Type of my bitmap or how do I convert a Bitmap into a Graphics?

thx hibbert
Offline  
Old 05-08-2007, 09:45 AM   #7 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8800
PIN: N/A
Carrier: n/a
Posts: 18
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

1. Open your JDE
2. Press Shift-F1
3. Search for Graphics class (make sure you're looking at the RIM native class help)
4. Look up the prototype for drawImage() method
5. Write your code to to confirm to that prototype
Offline  
Old 05-09-2007, 02:54 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by PeterK View Post
1. Open your JDE
2. Press Shift-F1
3. Search for Graphics class (make sure you're looking at the RIM native class help)
4. Look up the prototype for drawImage() method
5. Write your code to to confirm to that prototype
ok, i looked at it, but i can't make me a cake out of it
But i don't know why, now it works, I used the same code as the last time....
hmm ok now it works

thx so far for your help
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.