BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 12-04-2007, 07:13 AM   #1
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default new screen -> listField Problem

Please Login to Remove!

Hi,
i've got a problem by using a listField on a new screen.
I choose a menuItem from the mainScreen an a new Screen appears.
On this new screen is a new, empty listField.
Now I want to add some Items to this listField, i tried this method, but i still get some errors like "sourcecode is not availeble"

So here some peaces of my source:
Code:
// ----- MAINSCREEN ---
 _menuItem= new MenuItem("MyItem", 100000, 10) {
            public void run(){
                _anforderung = new anforderung();
                _anforderung.makeScreen();
            }
        };

// -------------- NEW CLASS -------------
package OrdnerApp;

import java.io.*;
import ....

public class anforderung {
    public MainScreen myScreen;
    
    public int makeScreen() {
        myScreen = new MainScreen();
         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);
        myScreen.add(myList);
        
        
        myScreen.setTitle("Test");
        UiApplication.getUiApplication().pushScreen(myScreen);
        return 0;
    }
   
}
So how can i simply add some Items to this listField? I looked in the manule for some examples but if i tried them out there were alwasy the same errors like now, so please help me !!

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-04-2007, 07:39 AM   #2
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

You can use ObjectListField which already implements itself as a listener.
I'd also suggest not to use anonymous screens but let each screen have its own class extending MainScreen.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-04-2007, 08:57 AM   #3
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

ok thanks for your tip.
you said i should put each screen into one class for itself? if so, how do i do that?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-04-2007, 09:20 AM   #4
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

you create a new file, give it a name like ActionsScreen.java
Define the class, extend MainScreen and build the screen using the constructor. And put the screens in an own package if you have more of them to keep your project neat.

Code:
public class ActionsScreen extends MainScreen {
private EditField testField;

public ActionsScreen(){
	testField=new EditField("","test");
	add(testField);
	}
}
To let your screens interact with your application you can (dirty) give them the application in the constructor or (clean) give them an interface that is implemented by your application.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-04-2007, 09:50 AM   #5
pa4o85
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Default

I use my own list field. The implementation is like this:
Code:
public class ListBoxField extends VerticalFieldManager implements DrawStyle {
  
  private int listBoxWidth;
  private int listBoxHeight;
  
  private Font font;
  
  public ListBoxField(List appsNames, Font font, long style) {
    super(style);
    this.font = font;
    listBoxWidth = Display.getWidth() - 32;
    listBoxHeight = 3 * font.getHeight();
    
    VerticalFieldManager vfm = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    
    Label label = null;
    for (int i = 0; i < appsNames.size(); i++) {
      label = new Label(cutName((String) appsNames.get(i)), listBoxWidth, font, Field.FOCUSABLE);
      vfm.add(label);
    }
    add(vfm);
  }
  
  private String cutName(String text) {
    if (font.getAdvance(text) <= 202) {
      return text;
    } else {
      int i = 0;
      while (font.getAdvance(text) > 202) {
        int index = text.lastIndexOf(' ');
        if (index == -1) {
          index = 35 - i;
          i++;
        }
        text = text.substring(0, index);
      }
      return text + "...";
    }
  }
  
  public void paint(Graphics g) {
    g.drawRect(0, 0, listBoxWidth, listBoxHeight);
    super.paint(g);
  }
  
  public void sublayout(int width, int height) {
    super.sublayout(listBoxWidth, listBoxHeight);
    setExtent(listBoxWidth, listBoxHeight);
  }
  
  public int getPreferredHeight() {
    return listBoxHeight;
  }

  public int getPreferredWidth() {
    return listBoxWidth;
  }
  
}
You just make an instance of this class and add the field to your main screen.
Code:
    ListBoxField list = new ListBoxField(names, plainFont, Manager.NO_VERTICAL_SCROLL);
Good Luck!
Offline  
Old 12-04-2007, 09:59 AM   #6
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

hey thanks a lot!!

that is exactly what i was looking for =)

now i just have to know how to dispose or pop the screen from a menu-point of the new main screen... i will use the searchfunction.

thanks a lot again =)

hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 12-04-2007, 11:31 AM   #7
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

UiApplication.getUiApplication().popScreen(this)
or, more elegant, using the interface of the main application that provides control.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 12-05-2007, 02:35 AM   #8
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default

thanks, i found this one here in the forum:
Code:
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Advance 71A6592  Ballast CW Autotransformer 1000W M47 Philips picture

Advance 71A6592 Ballast CW Autotransformer 1000W M47 Philips

$59.99



4 Count Case GE ProLine 2 Bulb 120V T12 Electronic Fluorescent Light Ballasts picture

4 Count Case GE ProLine 2 Bulb 120V T12 Electronic Fluorescent Light Ballasts

$49.99



Advance RL2SP20TP Magnetic Ballast. New In Box RL-2SP20-TP picture

Advance RL2SP20TP Magnetic Ballast. New In Box RL-2SP20-TP

$34.00



Ballast for Induction Lamp 200W - 120V /277V - New / Open Box - Ark Lighting picture

Ballast for Induction Lamp 200W - 120V /277V - New / Open Box - Ark Lighting

$22.22



Phillips Advance ICF-2S26-H1-LD Electronic Compact Fluorescent Ballast 12 Pack picture

Phillips Advance ICF-2S26-H1-LD Electronic Compact Fluorescent Ballast 12 Pack

$250.00



Lot Of 3 Philips Advance ICN-2S110-SC Ballast ICN2S110SC picture

Lot Of 3 Philips Advance ICN-2S110-SC Ballast ICN2S110SC

$45.99







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