BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 12-04-2007, 07:13 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 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 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (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 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 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (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

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 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (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

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


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.