开发者

Customize listfield item on BlackBerry

开发者 https://www.devze.com 2023-01-27 09:55 出处:网络
I have a simple list field class which shows the default menu when I select a particular listitem. I want to customize the listfield item, so that when an item is selected a new screen is pushed onto

I have a simple list field class which shows the default menu when I select a particular listitem. I want to customize the listfield item, so that when an item is selected a new screen is pushed onto the stack. I am overridding trackwheeel() method, but am not able to make it work.

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import java.util.Vector;



public class TeamListScreen extends UiApplication
{
     public static void main(String[] args)
     {
      TeamListScreen theApp = new TeamListScreen();
         theApp.enterEventDispatcher();
     }
     public TeamListScreen()
     {
         pushScreen(new ListFieldScreen());
     }
} 

class ListFieldScreen extends MainScreen
{
    private ListField _listField;
    private Vector _listElements;
    int listFieldIndex = -1;

    public ListFieldScreen() 
    {
        setTitle("List Field Sample");

_listElements = new Vector(); 
_listField = new ListField();
ListCallback _callback = new ListCallback();
_listField.setCallback(_callback);
_listField.setRowHeight(45);
//_listField.setChangeListener(this);
add(_listField);
initializeList();
_listField = new ListField(_listElements.size()) {

 protected void drawFocus(Graphics graphics, boolean on) {
 }

 protected boolean trackwheelClick(int status, int time) {

  listFieldIndex = _listField.getSelectedIndex();

  if (listFieldIndex < 0) {
   listFieldIndex = 0;

  }
  try {
   UiApplication.getUiApplication().invokeLater(new Runnable() {
    public void run() {
     UiApplication.getUiApplication().pushScreen(new LiveScreen());
     // UiApplication.getUiApplication().popScreen(getActiveScreen());
    }
   });
  } catch (Exception e) {
  }
  return开发者_开发知识库 true;
 }

};


}

private void initializeList()
{
    String itemOne = "List item one";
    String itemTwo = "List item two";
    _listElements.addElement(itemOne);
    _listElements.addElement(itemTwo);
    reloadList();
}
private void reloadList()
{
    _listField.setSize(_listElements.size());
}

private class ListCallback implements ListFieldCallback 
{
    public void drawListRow(ListField list, Graphics g, int index, int y, int w) 
    { 
       String text = (String)_listElements.elementAt(index); 
        g.drawText(text, 0, y, 0, w); 
    } 
    public Object get(ListField list, int index) 
    {
        return _listElements.elementAt(index); 
    } 
    public int indexOfList(ListField list, String prefix, int string) 
    { 
        return _listElements.indexOf(prefix, string); 
    } 
    public int getPreferredWidth(ListField list) 
    { 
        return Display.getWidth(); 
    } 
}
}


trackwheelClick() function is deprecated, you should use navigationClick() instead.

BTW, you don't need to use UiApplication.getUiApplication().invokeLater, because it is already running in the event queue.

0

精彩评论

暂无评论...
验证码 换一张
取 消