ListField selected?

How do I know if an item is selected in a ListField? The documentation says that getSelectedIndex returns-1 if an item is not selected, but when I fill my list then check if on is selected, the following code always runs if the list contains elements.

If (editList.getSelectedIndex () >-1) {}

}

When I check the value of getSelectedIndex(), it is 0 if there is no selected item, or if the first element is selected and something greater than 0 if the other items are selected. So, what is a reliable way to only do something if an item is selected in the list.

also, really dumb question, how you define MultiSelect on a ListField?  I wonder maybe if I need that goes out to make this work as I want to and the docs don't tell how to use the fields.

It seems that the documentation is confusing, as the ListField will return the index of the last selected element.  Take a look at this thread - you can use 'getLeafFieldWithFocus()' to determine the currently selected field and if it is not centered, assumes that the index is - 1.

See this thread:

Problem with the ObjectListField

http://supportforums.BlackBerry.com/Rim/Board/message?board.ID=java_dev&message.ID=26369

You use MULTI_SELECT in the style of the constructor - see setting

Public ListField (int numRows, long style)...

Tags: BlackBerry Developers

Similar Questions

  • get all the items you selected / checked

    Hello

    How all the items selected in a list that can be read?

    I need get all items (enabled) in the list and fill a vector...

    I get not all selected items, I only get the element on which is currently...

    Help, please

    Hello

    Exactly what I wanted to say, you need to implement this thing on yourself.

    I will try to explain the step hope it will help

    (1) create an array whose length is the same as listField.Intialize this table by 0 which means initially no element is selected.

    (2) each position in the table represent the listField position.

    (3) to each selection on listField change the corresponding value in table 1, for example if you select 2 point listField change the value in position 2 in table 1, if you select again the same option to new swtich tha value to 0.

    (4) Finally, when you want to extract the value of the selected item in the listfield, select all the table position with the value 1.

    I tried to explain the hope it will help you.

  • Selects a line in a ListField

    I have a ListField in my application and I want to allow the user to select several lines that are not necessarily side by side.  Selection of lines 0, 3, 5, 9 and 10 for example.  How can I allow this behavior with a ListField?

    Thank you.

    It is not supported, but you can implement it yourself (as selected by hand, paint lines create a method getSelected etc.)

  • Selected line in ListField

    Hello everyone,

    I have a bug in the display of a listfield.

    In my application, I use a field list that contains several lines. On the screen, I display only 5 rows.

    When I select a line, a new screen is pushed on the screen. Now, I save the index of the selected row.

    I press return key, it displays my listfield but selected lines still appears on the bottom of the screen.

    I like to keep the same position of the line on the screen.

    Does anyone have an idea to do this?

    Thanks in advance

    THX Simon, but unfortunately it does not work.

    Even if I do not push the new behavior of the screen is the same:

    • My list contains 10 items
    • I displays only 5 of them on the screen.
    • I navigate to the 8th item and click on it.
    • I save the selected index and update the list of selected index together with index recorded previously.
    • The selected line is worn correctly, but it still appears at the end of the list that appears. I want it keep the same place.
  • How to make the lines selectable listfield, when the list has been added to a dialog box

    Hello

    I added a listfield to a dialog box. Now I want that when I click on a line any of this list field, I should get a menu (i.e. something should be available for me so that I can perform an action on the selected line). But when I click on the line, nothing happens.

    Help, please

    Create your own screen, its less than the actual display dimensions to make it look like a pop-up screen. When a line is selected/clicked, call makeMenu.

  • Border around the selected ListField item?

    Hello

    I wonder if it is possible to customize a ListField, such as when you scroll through the list, the current row will have a border color around it?

    If this is not possible, I thought to imitate a ListField behavior using a TableLayout, where each row in the table has a HorizontalFieldManager.  Then, when an individual HorizontalFieldManager is selected, it will draw a border around it...

    Also, would it be possible to have a border around the current selected line (whether in a listfield or tablelayout) and then be able to select an object (such as a button) inside the line, without losing the border highlighted?

    Thank you!

    You might expect to have a special identification for the selected line in a ListField was asked and answered several times on this forum.  From memory, there are two options:

    (a) substitute drawfocus

    (b) in your drawListRow, check if the line that you draw is the selected line of the ListField.

    I suggest that you look in the forum for more information on these options.

    A ListField is a unique field, with a line at a time selected.  Without coding you something special it is not possible to have different parts of the line selected in different circumstances.  And although it is possible, don't normally add you a HorizontalFieldManager (or all other fields) to the ListField and which allows to paint content,

    What you're suggesting is indeed possible, but it is not for the faint-hearted.  I would recommend that investigate you other ways to achieve the desired effect before you start to look at using other fields to the layout and paint a line in the ListField.

  • How to get the element selected listfield and goto next page?

    Assalaamualikum

    I try parsing the XML from a url and show in listfield.

    problem:

    How to get the selected item and passing the variable and than goto next page?

    my code:

    package parsepack;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Vector;

    Import javax.microedition.io.Connector;
    Import javax.microedition.io.StreamConnection;

    Import net.rim.device.api.system.Bitmap;
    Import net.rim.device.api.system.Display;
    Import net.rim.device.api.ui.DrawStyle;
    Import net.rim.device.api.ui.Field;
    Import net.rim.device.api.ui.FieldChangeListener;
    Import net.rim.device.api.ui.Graphics;
    Import net.rim.device.api.ui.Manager;
    Import net.rim.device.api.ui.UiApplication;
    Import net.rim.device.api.ui.component.ListField;
    Import net.rim.device.api.ui.component.ListFieldCallback;
    Import net.rim.device.api.ui.container.MainScreen;
    Import net.rim.device.api.ui.container.VerticalFieldManager;
    Import net.rim.device.api.xml.parsers.DocumentBuilder;
    Import net.rim.device.api.xml.parsers.DocumentBuilderFactory;

    to import org.W3C.DOM.document;
    Import org.w3c.dom.Node;
    Import org.w3c.dom.NodeList;

    extends xmlparsing public class UiApplication implements ListFieldCallback, FieldChangeListener
    {

    Public Shared Sub main (String [] args)
    {
    xmlparsing app = new xmlparsing();
    app.enterEventDispatcher ();
    }

    public long mycolor;
    Connection _connectionthread;
    private static ListField _list;
    private static Vector listElements is new Vector();.
    public display display = new MainScreen();
    MainManager VerticalFieldManager;
    VerticalFieldManager subManager;

    public xmlparsing()
    {
    Super();
    pushScreen (screen);

    final Bitmap Imagearriereplan = Bitmap.getBitmapResource ("blackbackground.png");

    mainManager = new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL |) Manager.NO_VERTICAL_SCROLLBAR)
    {

    public void paint (Graphics graphics)
    {
    graphics.drawBitmap (0, 0, Display.getWidth (), Display.getHeight (), Imagearriereplan, 0, 0);

    Super.Paint (Graphics);
    }

    };

    subManager = new VerticalFieldManager(Manager.VERTICAL_SCROLL |) Manager.VERTICAL_SCROLLBAR)
    {
    protected void sublayout (int maxWidth, maxHeight int)
    {
    int displayWidth = Display.getWidth ();
    int displayHeight = Display.getHeight ();

    Super.sublayout (displayWidth, displayHeight);
    setExtent (displayWidth, displayHeight);
    }
    };

    Screen.Add (mainManager);

    _list = new ListField()

    {

    public void paint (Graphics graphics)

    {
    graphics.setColor ((int) mycolor);
    Super.Paint (Graphics);

    }

    };
    myColor = 0x00FFFFFF;
    _list. Invalidate();
    _list.setEmptyString ("* only supplies not available *", DrawStyle.HCENTER "");
    _list.setRowHeight (50);
    _list.setCallback (this);
    mainManager.add (subManager);
    listElements.removeAllElements ();
    _connectionthread = New Connection();
    _connectionthread. Start();
    }

    protected boolean navigationClick (int status, int time)
    {
    Try
    {
    Here, go to another screen if you need.

    }
    catch (System.Exception e)
    {
    System.out.println ("Exception:-: navigationClick()" + try ());
    }
    Returns true;
    }

    private class login extends thread
    {
    Public connection()
    {
    Super();
    }

    public void run() {}
    Doc document;
    StreamConnection conn = null;
    InputStream is = null;
    try {}

    Conn = Connector.open (StreamConnection) ("http://ec2-54-248-241-248.ap-northeast-1.compute.amazonaws.com/koperasi-akr-trial/cgi-bin/gw-pinjama...

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance ();
    docBuilderFactory.setIgnoringElementContentWhitespace (true);
    docBuilderFactory.setCoalescing (true);
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder ();
    docBuilder.isValidating ();
    is = conn.openInputStream ();
    doc = docBuilder.parse (is);
    doc.getDocumentElement () .normalize ();
    List of NodeList = doc.getElementsByTagName ("ID");
    for (int i = 0; i)< list.getlength();="" i++)="">
    Node node = list.item (i) .getFirstChild ();
    listElements.addElement (textNode.getNodeValue ());
    }
    } catch (Exception e) {}
    System.out.println (try ());
    } {Finally
    If (is! = null) {}
    try {is.close ();
    } catch (IOException ignored) {}
    } If (conn! = null) {}
    Try {conn.close () ;}
    catch (IOException ignored) {}
    }} UiApplication.getUiApplication () .invokeLater (new Runnable() {}
    public void run() {}
    _list. SetSize (listElements.Size ());
    subManager.add (_list);
    Screen.Invalidate ();
    }
    });
    }

    }

    ' public void drawListRow (list ListField, Graphics g, int index, int y, int w)
    {
    Your string = (String) listElements.elementAt (index);
    int yPos = 0 + y;
    g.drawLine (0, yPos, w, yPos);
    g.drawText (, 5, 15 + y, 0, w);
    }

    public {get {Object (ListField list, int index)
    {
    Return listElements.elementAt (index);
    }
    public int indexOfList (String prefix, ListField list, int, string)
    {
    Return listElements.indexOf (prefix, string);
    }
    public int getPreferredWidth (ListField list)
    {
    Return Display.getWidth ();
    }
    public final void insert (String toInsert, int index) {}
    listElements.addElement (toInsert);
    }

    ' Public Sub fieldChanged (field field, int context) {}

    }
    }

    Thank you.

    I told you that replace the navigationclick() method where initialize you your listfield

    as I think that changing your code and then answer me

    _list = new ListField()
    {
    protected boolean navigationClick(int status, int time)
    {
      Dialog.inform("hi");
      return true;
    }
    
    public void paint(Graphics graphics)
    {
    graphics.setColor((int) mycolor);
    super.paint(graphics);
    }
    };
    
  • ListField onFocus selection last element

    Hello

    ListField seems to be select the last item in the list by default when it gets focus for the first time on a screen. Subsequent navigations between other fields in the form and the listfield seem to function normally (first elmt is picked up first).  Does anyone have an idea why this is happening?

    Thank you

    Teja.

    Sorry misunderstood.  I'm not sure. Never seen that before.  You're doing a setSelectedIndex?

  • ListField - how to get the selected items

    Hi @all,

    I am running OS5 on a BB bold 9700 and development via eclipse.

    I tried to do a listfield and put it in a display of network manager, which works very well.

    As peter_strange did in a reply to a thread listfield, I tried to catch the click button on navigation through "makemenu.

    It works fine, but after processing the code according to the listfield (getindex), it shows a standard menu, which I don't want. I want just to get the index or the name of the current or selected fields and continue with the transformation by showing a new screen for example.

    In some other threads that I found excerpts concerning 'navigationclick', but I don't understand, what I have to do here and why. Th KB, I searched but I did find something to go further.

    Someone there who can help me with a small example?

    Thank you much in advance.

    CUA

    Michael

    You can create your own class or override her anonymously.

    new ListField (...) {replace the code of the method here}

    (blackberry is perhaps not the best way to start learning java...)

  • Delete selection listfield unfocus?

    ... Is semms listfield for keep the last item selected when the update leave the listfield there a way to display each item as disabled when the update leave the listfield?

    Thank you!

    In short, what a setting when focus is moved (it's not quite true, but enough for this topic):

    (1) object Graphics Setup with the default settings for the field non-(including color)

    (2) graphic in the field that had the focus for re-painting

    (3) object Graphics Setup with the default settings for the field target (including color)

    (4) go graphic in the field that focus receives for the painting of the target area

    If you just need properly paint focus, you can change your status

    if(listField.getSelectedIndex() == index)
    

    in the drawListRow method for

    if(graphics.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS))
    

    Important here is what is happening in step 2 when the control is asked to re - paint himself to clear the update. Last row is painted as focused because your condition is true for the last row when control.

    My idea is simple: If you want to you want to customize the style for focus - do only when the update area is painted rather than each time control is redrawn. And framework will do the rest for you.

    Edit: a few typos in the description including significant in step 3 description

  • ListField.getSelectedIndex &gt; = 0, even if not selected.

    does anyone know why ListField.getSelectedIndex always returns the value > = 0, even if nothing is selected? the docs say it should return-1 if nothing is selected... also ListField.isFocus () are always false. is it because if a menu is open then listbox loses focus?

    NM, found the solution at the end of this thread: http://supportforums.blackberry.com/t5/Java-Development/Problem-with-ObjectListField/td-p/190756/pag...

    It seems that the docs are wrong.

  • How do I not selectable Listfield?

    Hello

    I have a listfield. In one case (when the user chooses an option button 2), I don't want this list to be selected by the user. So I want to remove the selection on this listfield in selection of radio button 2. I'm trying to solve this problem under fieldChanged with the following code:

    _lst.setEmptyString("",0);
    _lst.setSize(0);
    _lst.select(false);
    _lst.selectionDelete();
    _lst.setEditable(false);
    _lst.setSelectedIndex(-1);
    

    But it does not work as my expectation. With this code, I do not see the content of the list as expected, but able to select a line, which is of first rank, which is empty. I want to do the entire list to be unselectable.

    Please sugegst me how can I solve this problem?

    Thank you.

    FieldChangeListener and your custom ListField are completely independent. When you create your ListField, override its method of isFocusable() to take into account a flag value in turn depending on your state of the checkbox. This dependence can be established by setting FieldChangeListener on your field check box.

    Read the docs on the field. isFocusable () and it will become apparent.

  • Scrolling AND selecting items in a ListField on the storm?

    Background information:

    BlackBerry Storm 9500

    BlackBerry JDE 4.7.0

    Problem:

    I use a ListField to display several items in a list. I also use the touchEvent (TouchEvent message) method to listen to a click (TouchEvent.CLICK). Well, everything seems to work except when I need to scroll through the list. It seems that using the touchEvent method, I can't scroll through the list. If I remove the touchEvent method, scrolling works but I am unable to use the touch interface to select an item in the list by clicking on it.

    Question:

    Is it possible to get both? In other words, can enable scrolling in the ListField AND allow the user to select an item by clicking on it?

    Code:

    private class SlideList extends screen

    {

    Fields

    private ListField _list;

    Private _callback ListCallback;

    Constructor

    public SlideList()

    {

    Super();

    Add a title screen

    LabelField title = new LabelField (getTitle (), LabelField.ELLIPSIS |) LabelField.USE_ALL_WIDTH);

    setTitle (title);

    setupList();

    }

    Private Sub setupList()

    {

    If (_list! = null)

    Delete (_list);

    Get all the slides and put their titles and subtitles in a table

    String [] slideTitles = getSlideTitles();

    _list = new ListField();

    _callback = new ListCallback();

    _list.setCallback (_callback);

    Build the list of exercise.

    for (int index = 0; index)

    {

    _list. Insert (index);

    _callback. Insert (slideTitles [index], index);

    }

    _list.setSelectedIndex (currentSlideNum);

    Add (_list);

    }

    Get the touch input.

    protected boolean touchEvent (TouchEvent message)

    {

    If (message.getEvent () is TouchEvent.CLICK)

    {

    Check if a list item is selected.

    If (_list.getSelectedIndex () > - 1).

    {

    Dialog.Alert ("you selected:" + _list.getSelectedIndex ());

    itemSelected (_list.getSelectedIndex ());

    Returns true;

    }

    on the other

    Returns false;

    }

    on the other

    Returns false;

    }

    Private Sub itemSelected (int listIndex)

    {

    currentSlideNum = listIndex;

    displaySlide();

    UiApplication.getUiApplication () .popScreen (this);     Remove this screen to display the program.

    }

    private class ListCallback implements {ListFieldCallback}

    private vector listElements = new Vector();

    ' public void drawListRow (list ListField, Graphics g, int index, int y, int w)

    {

    String text = (String) listElements.elementAt (index);

    g.drawText (text, slideIcons [index] .getWidth () + 10, y, 0, w);

    }

    public Object get (ListField list, int index) {}

    Return listElements.elementAt (index);

    }

    public int indexOfList (String p, ListField list, int s) {}

    Return listElements.getSelectedIndex ();

    Return listElements.indexOf (p, s);

    }

    public int getPreferredWidth (ListField list) {}

    Display sr = UiApplication.getUiApplication () .getActiveScreen ();

    Return sr.getWidth ();

    }

    public final void insert (String toInsert, int index) {}

    listElements.insertElementAt (toInsert, index);

    }

    {} public void erase()

    listElements.removeAllElements ();

    }

    }

    }

    Mark,

    Thanks for your reply. It turns out that the solution I was looking for was very simple. Rather than return

    fake

    in the touchEvent method, I back

    super.touchEvent (message)

    While touchEvent can call its parent class and always look for other events inherent in a listenField, such as scrolling with a finger.

    It now looks like this:

    Get the touch input.

    protected boolean touchEvent (TouchEvent message)

    {

    If (message.getEvent () is TouchEvent.CLICK)

    {

    Check if a list item is selected.

    If (_list.getSelectedIndex () > - 1).

    {

    Dialog.Alert ("you selected:" + _list.getSelectedIndex ());

    itemSelected (_list.getSelectedIndex ());

    Returns true;

    }

    }

    Return super.touchEvent (message);

    }

  • How to select an item in a listfield

    Hello guys,.

    I'm trying to use a FieldChangeListener to get the item list, click on the touch keys and navigation, but with no joy. I tried to use ListChangeListener, but who needs signature, I think. Also I use navigationClick, that works, but I'm not 100% use it to check if it was a touch on the screen, tank or the keyboard navigation wheel...

    Could you please tell me about the best way to go about this?

    Concerning

    Wes

    Thanks for the replies guys, I managed to find a solution to this problem by adding the following to my code:

    protected boolean touchEvent(TouchEvent message) {    switch (message.getEvent()) {    case TouchEvent.CLICK:        fieldChangeNotify(1);        // fall through    case TouchEvent.UNCLICK:        return true;    }    return super.touchEvent(message);}
    
  • Help connect to a return address listfield on-screen who called it with the selected data.


    "I'm ashamed to say.

    No need to be ashamed, why reinvent the wheel?

    A way I use to transmit back data is as follows:

    getAddressContacts extractScreen = new getAddressContacts();

    UiApplication.getUiApplication () .pushModalScreen (extractScreen (;)

    Contact extractedContact = extractScreen.getExtractedContact ();

    To use it, you add a getExtractedContact method to the screen of your getAddressContacts and make sure that it can return the contact of the extract.

    Make sense?

    Note: In the original post, the pushModalScreen was hurt just a pushScreen.  This note fixed to help future readers, intended to reduce confusion for anyone who reads on.

Maybe you are looking for