Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My answer will be along the lines of <a href="https://stackoverflow.com/questions/1601887/how-do-you-make-a-dropdown-list-that-displays-images-to-the-user-instead-of-text/1602477#1602477">jitter's response</a>. The general idea for the kind of customizations that you want is to override the default behavior of the basic components.</p> <p>Suppose, the choices that you want to display can be encapsulated by a class named <strong><code>Choice</code></strong> declared as follows:</p> <pre><code>private class Choice { public Bitmap image; public String label; public Choice(String name) { this.image = Bitmap.getBitmapResource(name + ".png"); this.label = name; } public String toString() { return this.label; } } </code></pre> <p>then you can declare an <strong><code>ObjectListField</code></strong> instance as:</p> <pre><code>ObjectChoiceField choice = new ObjectChoiceField() { protected void paint(Graphics graphics) { // Get the current selected Choice Choice item = (Choice) this.getChoice(getSelectedIndex()); int xOffset = 5; // 5 px padding on the left graphics.drawBitmap(xOffset, 0, item.image.getWidth(), item.image.getHeight(), item.image, 0, 0); // Add text after the image and 10px padding. xOffset += item.image.getWidth() + 10; graphics.drawText(item.label, xOfffset, 0); } }; </code></pre> <p>set your choice items as:</p> <pre><code>choice.setChoices(new Choice[]{ new Choice("choice 1"), new Choice("choice 2")}); </code></pre> <p>and then add it to your <strong><code>Screen</code></strong> (or <strong><code>FieldManager</code></strong> of your choice) using:</p> <pre><code>add(choice); </code></pre> <p>I have not been able to override the actual selection pop-up menu items. This seems to call the <code>toString()</code> method of your choice items. That is why I have overriden the default implementation of <code>toString()</code> in the <strong><code>Choice</code></strong> class so that we can display logical names in that pop-up.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload