aspose file tools*
The moose likes Java Micro Edition and the fly likes Current focused item in the form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Current focused item in the form" Watch "Current focused item in the form" New topic
Author

Current focused item in the form

shah isha
Greenhorn

Joined: May 01, 2007
Posts: 18
Hi,
I am developing one application in which i have one form containing 3 textfields.. My prob is i want to know which textfield is selected on the form...How can i dot that? I know there is one boolean varibable in item class but its not allowing me access to that??

Reply me if nebody know the solution..

[ May 02, 2007: Message edited by: shah isha ]
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Isha,

What is the MIDP version you are using ?

Regards,
Arnab
shah isha
Greenhorn

Joined: May 01, 2007
Posts: 18
Hi Thanks for your reply..
I am using MIDP 2.0.
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Hi Isha,

You can use ItemStateListener to find out which item is currently being used.

However, I think to capture this the item needs to be changed for example you need to type in something in the textfield which will change the item and you can capture the item being changed.

Arnab
shah isha
Greenhorn

Joined: May 01, 2007
Posts: 18
Hi Arnb,
You are right.. It didnt work as i need to type something in textfield than only state will get changed.
But i got the solution.. I had to add itemCommandListener..
and add command as default command to the item.. and implemented

public void itemCommandAction(Command c,Item i)

It solved my problem
[ May 03, 2007: Message edited by: shah isha ]
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
Thanks Isha for the solution. So this means you need to add a command to each item of the form. Right ?

Arnab
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
So the default item Command is triggered when the item comes into focus?

Can you put across few lines of code...


Theepan Thevathasan
SCJP 1.4, SCWCD 1.4, SCMAD 1.0 SCBCD 1.3, MCP(.Net Frm 2.0 App Dev Fdn)
shah isha
Greenhorn

Joined: May 01, 2007
Posts: 18
Hi here am seding sample code,
Try it..

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

public class TwoTextTest extends MIDlet implements CommandListener,
ItemCommandListener
{
public void startApp()
{

txtFirstItem.setDefaultCommand(editCommand);
txtFirstItem.setItemCommandListener(this);
txtSecondItem.setDefaultCommand(editCommand);
txtSecondItem.setItemCommandListener(this);
mainForm.append(txtFirstItem);
mainForm.append(txtSecondItem);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
Display.getDisplay(this).setCurrent(mainForm);
}
public void pauseApp()
{
}

public void destroyApp(boolean unconditional)
{
}

public void commandAction(Command command, Item item)
{
if(item == txtFirstItem)
{
Alert alert = new Alert("Info:", "First text field selected!",
null, AlertType.INFO);
Display.getDisplay(this).setCurrent(alert);
}
else if(item == txtSecondItem)
{
Alert alert = new Alert("Info:", "Second text field selected!",
null, AlertType.INFO);
Display.getDisplay(this).setCurrent(alert);
}
}

public void commandAction(Command command, Displayable displayable)
{
if(command == exitCommand)
{
Display.getDisplay(this).setCurrent(null);
destroyApp(true);
notifyDestroyed();
}
}

private Form mainForm = new Form("Example");
private TextField txtFirstItem = new TextField("first item", "FIRST", 20, TextField.ANY);
private TextField txtSecondItem = new TextField("second item", "SECOND", 20, TextField.ANY);
private static final Command editCommand = new Command("Check", Command.ITEM, 1);
private static final Command exitCommand = new Command("Exit", Command.EXIT, 1);
}


Here notice that the default command which you have added will be shown only if that textfield is focused which is good

Regards,
Isha
[ May 07, 2007: Message edited by: shah isha ]
Deepan Devadasan
Ranch Hand

Joined: Jan 25, 2007
Posts: 226
Hi Isha...

This is so cool..

All these days i was reliant only on the ItemStateListener ...

The bad side of it is that, the trigger will be fired only when some one edits the fields....

I like the idea of defaultCommands...

Just a quick query..

I am implementing a Canvas for SplashScreen...

Is there a way i could bring in some concept like DISMISS_COMMAND that is found on the Alert...

If I could do something like that ...I can get to know when the splash screen goes off after the timer is triggered..

Thanks in advance
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Current focused item in the form