• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Current focused item in the form

 
shah isha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Isha,

What is the MIDP version you are using ?

Regards,
Arnab
 
shah isha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Thanks for your reply..
I am using MIDP 2.0.
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the default item Command is triggered when the item comes into focus?

Can you put across few lines of code...
 
shah isha
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic