Skip to content

Instantly share code, notes, and snippets.

@ChrisMwai
Created February 12, 2014 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisMwai/8964400 to your computer and use it in GitHub Desktop.
Save ChrisMwai/8964400 to your computer and use it in GitHub Desktop.
Simplest way to get contacts in s40(J2ME) with LWUIT.
package com.exqitsolutions.numberTest;
/*
*@author Chris
*/
import com.sun.lwuit.Form;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.TextField;
//include the other nescessary packages
public class Field extends MIDlet{
public Form numForm;
public TextField num;
public void startApp(){
//initialize display, theme and other optional packages
//AnimatedGifFactory falls here
ReadContacts();
}
public void ReadContacts(){
numForm = new Form("Get Contacts");
numForm.setLayout(new BorderLayout());
num = new TextField();
num.setConstraint(TextField.PHONENUMBER);//this is so important!!
num.setHint("Number");
numForm.addComponent(BorderLayout.CENTER, num);
numForm.show();
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
}
@ChrisMwai
Copy link
Author

Explanation(not nescessary though, but still
...):

  • When a LWUIT TextField has two commands that show when active, T9 and Clear.
  • Setting the TextField's constraint to PHONENUMBER does the whole job. When a user presses T9, the TextField behaves like an LCDUI TextField with a search command.
  • When the user presses the search command, it displays the phone's contact list.
  • Any contact the user selects will have the number associated with it added to the field.

Simple!!!

NB: This is a second gist, couldn't delete the first one. There might be an error or two up there, I typed this on my phone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment