You Are Here:

Community: Developer Discussion Boards

#1 Old TextField selected - 2006-06-29, 11:27

Join Date: Jun 2006
Posts: 50
decisor
Offline
Regular Contributor
Hi,

Can anyone could tell me how can I know wicth texfield is selected or have the focus?

My goal is that I have two TextField's and for each one I have two different screens with ChoiceGroup to fill after do the correct choice. I have a command that go to the correct screen.
What I want is when the focus is in TextField1 and when I press command it go's to Screen1. When the focus is in TextField2 and same command is pressed it go's to Screen2.


Can ayone help me on this?


Thanks,
decisor
Reply With Quote

#2 Old Re: TextField selected - 2006-06-29, 18:01

Join Date: Mar 2006
Posts: 518
wang_shui
Offline
Super Contributor
Hi,

U can do this way.
Add the same command,say Okcommand both the items (Textfield1 & Textfield2) rather than to the form as a whole.
Then set the itemcommandlistener to the two items.
U can get the commandAction(Command c, Item item) based on the item of which the focus is now enabled.

Hope this is helpful. This is the one which comes to my mind first. someone else will post a more easier or staright way to do this.

Wang
Reply With Quote

#3 Old Re: TextField selected - 2006-06-29, 19:20

Join Date: Jun 2006
Posts: 50
decisor
Offline
Regular Contributor
Thanks wang_shui.

I will try and then let you know.


decisor
Reply With Quote

#4 Old Re: TextField selected - 2006-06-30, 00:40

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
hi decisor,

use setDefaultCommand to have better control (and less commands),

try sample:

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);
}


hth,
regards,
Peter
Reply With Quote

#5 Old Thumbs up Re: TextField selected - 2006-07-03, 14:03

Join Date: Jun 2006
Posts: 50
decisor
Offline
Regular Contributor
Hi peterblazejewicz,

Thank's a lot.... Works perfectly, for my needs :) :) :)!!!

Just kiding. Hope that helps another users too.



decisor
Reply With Quote

#6 Old Re: TextField selected - 2006-07-03, 18:01

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
Hi decisor,
glad that worked, I'm on my learning curve edge :D
cheers,
Peter
Reply With Quote

#7 Old Re: TextField selected - 2006-07-10, 18:01

Join Date: Jun 2006
Posts: 50
decisor
Offline
Regular Contributor
Hi again peterblazejewicz,


Can I do some like this using MIDP-1.0???

What the chances to do something similar?!??!?!?!?!?!?!

Thanks,
decisor



EDIT -------- 2006-07-10 17:53 -------------

I've already got the "solution". The question is that for running for example in Nokia 6600 I put CLDC-1.0 and MIDP-1.0 wicth is no need. The only thing needed it's putting CLDC-1.1 and MIDP-2.0.


Sorry guys.

Hope this help anyone.

decisor
Last edited by decisor : 2006-07-10 at 18:58.
Reply With Quote

#8 Old Re: TextField selected - 2006-07-10, 19:43

Join Date: Dec 2005
Posts: 1,696
Location: Europe/Poland/Warsaw
peterblazejewicz
Offline
Super Contributor
hi,


so to just answer it should be probably possible with setItemStateListener(listener) method from MIIPD 1.0,
not tested with real device but with S60 3rd edition emulator and WTK 2.2 emulator,
class declaration changed:
PHP Code:
public class TwoTextTest extends MIDlet implements CommandListenerItemStateListener 
adding text fields to form and binding listeners:
PHP Code:
mainForm.append(txtFirstItem);
mainForm.append(txtSecondItem);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(this);
mainForm.setItemStateListener(this);
Display.getDisplay(this).setCurrent(mainForm); 
listener:
PHP Code:
public void itemStateChanged(Item item) {
        
// do something with event

on Nokia emulator not only text edition is trapped but also focus change between items on forms, WTK emulator broadcast only text edition,

hth,
regards,
Peter
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
TEXTFIELD NAME 问题 tahwee Other Programming Discussion 关于其他编程技术的讨论 0 2006-04-10 08:24
newB - TextField issue tetsujin1979 Mobile Java General 2 2005-08-16 10:29
Cannot use textField after delete and insert in Form andretr Mobile Java Tools & SDKs 1 2004-08-03 14:33
TextField refresh problem with Nokia devices RalfHupfer Mobile Java General 1 2004-07-02 02:35
Simple TextField question. Thaks matteopiccioni Mobile Java General 1 2003-12-03 12:32

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia