J2ME List Image

This example illustrates how to create list with image symbol. In this example we are trying to create list using of List class.

J2ME List Image


List Image MIDlet Example

This example illustrates how to create list with image symbol. In this example we are trying to create list using of List class. The List class define in two type of constructors, that is:

  • List(String title, int listType)
  • List(String title, int listType, String[] stringElements, Image[] imageElements) 

The List class has following Methods:

  • append(String stringPart, Image imagePart):- This method is the integer type, which is used to append an element to the choice. 
  • delete(int elementNum):- This is the void type which deletes the element. 
  • getImage(int elementNum):- This is the Image type which gets the image.
  • getSelectedFlags(boolean[] selectedArray_return):- This is integer type method which has the state of a Choice and returns the state of all elements in the boolean array. 
  • getSelectedIndex():- This is the integer type which returns the index number of an element in the Choice that is selected. 
  • getString(int elementNum):- This method is used to get the String of the element.
  • insert(int elementNum, String stringPart, Image imagePart):- This is void type it inserts an element into the Choice just prior to the element specified. 
  • isSelected(int elementNum):- It gets the boolean value indicating whether element is selected or not. 
  • set(int elementNum, String stringPart, Image imagePart):- It sets the element to the specified element, replacing the previous contents of the element. 
  • setSelectedFlags(boolean[] selectedArray)
  • setSelectedIndex(int elementNum, boolean selected)
  • size()

The SELECT_COMMAND is used to recognized whether user select from list or not.




Source Code of ListImage.java 


import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ListImage extends MIDlet implements CommandListener{
  private Display display;
  private List list;
  private Command exit, next;
  private Image car, airplane, hotel, mobile, cartoon;
  String[] stringElements = {"Aero plane""Car""Hotel""Mobile"};
  public ListImage(){
  airplane = Image.createImage("/airplane.png");
  car = Image.createImage("/car1.png");
  hotel = Image.createImage("/hotel1.png");
  mobile = Image.createImage("/mobile_ico.png");
  cartoon = Image.createImage("/cartoon.png");
  }catch(Exception e){

  public void startApp() {
  display = Display.getDisplay(this);
  Image[] imageElements = {airplane, car, hotel, mobile};
  list = new List("List + Image", List.IMPLICIT, 
stringElements, imageElements

  next = new Command("Select", Command.SCREEN, 0);
  exit = new Command("Exit", Command.EXIT, 0);

  public void pauseApp() {}

  public void destroyApp(boolean unconditional){

  public void commandAction(Command c, Displayable s){
  int index = list.getSelectedIndex();
  if (c == next || c == List.SELECT_COMMAND) {
  Alert alert = new Alert("Selected""You have selected: 
+ list.getString(index

  + ".", cartoon, AlertType.INFO);
  display.setCurrent(alert, list);
  else if(c == exit){


Download Source Code




We have 1000s of tutorials on our website. Search Tutorials tutorials on our website.

Share on Google+Share on Google+

J2ME List Image

Posted on: October 14, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: J2ME List Image  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
October 10, 2012
List mage

October 10, 2012

June 28, 2013

hw cN i use images frm ma memory card?