J2ME- List with images

J2ME

List with images

You can add images to a list by specifying the image parameter of the append(Element, Image) of the list.

listObj.append("Item1",imageObject);

The imageObject can be created by using the createImage(Image_path) of the Image class.

Image imageObject=Image.createImage("/image.png");

Example:



import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class ListImage extends MIDlet implements CommandListener{
private Display display;
private Form form;
private TextField txtname,txtpassword;
private Command Cmdok, Cmdcancel,ba,select;
private List lst;

public ListImage() {
display = Display.getDisplay(this);

}

public void startApp() {
form=new Form("Login");
txtname=new TextField("User id:","",250,TextField.ANY);
txtpassword=new TextField("Password:","",250,TextField.PASSWORD);
Cmdok=new Command("Ok",Command.OK, 0);
Cmdcancel=new Command("Cancel",Command.CANCEL,0);

form.append(txtname);
form.append(txtpassword);
form.addCommand(Cmdok);
form.addCommand(Cmdcancel);
form.setCommandListener(this);
display.setCurrent(form);

}

public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

public void commandAction(Command c, Displayable s) {
if(c==Cmdcancel) notifyDestroyed();
else if(c==Cmdok) check();
else if(c==ba) display.setCurrent(form);
else if(c==select) showselecteditem();
}

public void check(){
if(txtname.getString().equals("dara") && txtpassword.getString().equals("123")){
showlist();
}
else{
Alert al=new Alert("Incorrect","Invalid login!",null, AlertType.ERROR);
display.setCurrent(al);
}
}

public void showlist(){
ba=new Command("Back",Command.BACK,0);
select=new Command("Select",Command.OK,0);
lst=new List("Select the item:",List.EXCLUSIVE);
Image m=null;
try{m=Image.createImage("/imglist.png");}catch(Exception e){}
lst.append("Item 1",m);
lst.append("Item 2",m);
lst.append("Item 3",m);
lst.append("Item 4",m);
lst.append("Item 5",m);
lst.addCommand(ba);
lst.addCommand(select);
lst.setCommandListener(this);
display.setCurrent(lst);
}

public void showselecteditem(){
String selectedvalue=lst.getString(lst.getSelectedIndex());
System.out.println(selectedvalue);
}

}

List with images 






Comments

Name:
Comment:
Enter the text:
CAPTCHA image

....................................................................................................................Home | Forum | About | Contact
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.
Copyright @ 2011-2013 worldbestlearningcenter. All Rights Reserved.
Home Programming Web DB & App Questions Exercises Tips Programs FAQs Download About
Computer-Wbest
Popular Pages
You might like