Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
branchcut
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified
Accepted Solution

IllegalStateException when re-adding a previously removed field

Code snippet that fails:

 

 

/**
* Depending on the value of homeScreen.mNumberEditField, the
* mHomeScreen.myTextField is removed or re-added after being
* removed. Does not work, when re-added an IllegalStateException
* is thrown.
*/
class MyEditFieldChangeListener implements FieldChangeListener {

HomeScreen mHomeScreen;

// the default state, where the mytextfield is showing
int STATE_DEFAULT = 1;

// we've removed the mytextfield
int STATE_MY_TEXTFIELD_REMOVED = STATE_DEFAULT + 1;

// current state
int curState = STATE_DEFAULT;


public NumberEditFieldChangeListener(HomeScreen homeScreen)
{
super();
mHomeScreen = homeScreen;
}

public void fieldChanged(Field field, int context)
{
if (context == PROGRAMMATIC)
{
// ignore "programmatic changes", whatever that means.
return;
}

if (field == homeScreen.mNumberEditField) {

int len = homeScreen.mNumberEditField.getTextLength();
switch (len)
{
case 0:

if (curState == STATE_MY_TEXTFIELD_REMOVED)
{
// throws IllegalStateException.
mHomeScreen.add(mHomeScreen.myTextField);
curState = STATE_DEFAULT;
}

break;
default:
// is it numeric?
if (isNumeric() == false)
{

// remove call log fields
if (curState == STATE_DEFAULT)
{
mHomeScreen.delete(mHomeScreen.myTextField);

curState = STATE_MY_TEXTFIELD_REMOVED;
}

}
break;
}
}

}

}

 

 

 

 

 

 

 

 

 

 

 

Please use plain text.
Developer
branchcut
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified

Re: IllegalStateException when re-adding a previously removed field

 

I found a solution that seems to work:

 

Instead of calling 

 

 

mHomeScreen.add(mHomeScreen.myTextField); ... mHomeScreen.delete(mHomeScreen.myTextField);

 

 I tried using

 

 

mHomeScreen.getMainManager().add(mHomeScreen.myTextField); .. mHomeScreen.getMainManager().delete(mHomeScreen.myTextField);

 

 and the error went away.

 


 

 

Please use plain text.
Developer
branchcut
Posts: 37
Registered: ‎10-17-2008
My Device: Not Specified

Re: IllegalStateException when re-adding a previously removed field

 

The main issue is solved, but some follow up questions:

 

  1. What does it mean when the fieldChanged callback is called back with context == PROGRAMMATIC?
  2. Is the callback happening on the main UI thread on this case?  I was confused if I needed to use invokeLater() or not.  (I need to reread the docs that explain that .. any links would be helpful).
Please use plain text.
Administrator
MSohm
Posts: 14,519
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: IllegalStateException when re-adding a previously removed field

Programmatic changing of a field is a software change, such as calling setText on an EditField instead of a user actually typing.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.