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
New Contributor
Posts: 8
Registered: ‎07-22-2008
My Device: Not Specified
Accepted Solution

Detecting Selection from AdvancedUI template

Hello,

I have modified the UIExampleListStyleButtonFieldScreen class from the AdvancedUI example code.  I'm having problems performing actions based on the users selection.  I can see that "field" is equal to the appropriate label, but I can't seem to get it to pull the right URL or take other actions based on the selection.  I'm trying to create an if statement within public void fieldchanged to determine which was selected.  Any thing to point me in the right direction would be much appreciated:

 

public class UIExampleListStyleButtonFieldScreen extends UIExampleScreen implements FieldChangeListener
{
private UIExampleScreen _explanation;

public UIExampleListStyleButtonFieldScreen() {

super( NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );

setTitle("TU Mobile");

Bitmap caret = Bitmap.getBitmapResource( "chevron_right_black_15x22.png" );

ListStyleButtonField one = new ListStyleButtonField( "News", caret );
one.setChangeListener( this );
add( one );

ListStyleButtonField two = new ListStyleButtonField( "Events", caret );
two.setChangeListener( this );
add( two );

ListStyleButtonField three = new ListStyleButtonField( "Admissions", caret );
three.setChangeListener( this );
add( three );

ListStyleButtonField four = new ListStyleButtonField( "Athletics", caret );
four.setChangeListener( this );
add( four );

ListStyleButtonField five = new ListStyleButtonField( "Give to TU", caret );
five.setChangeListener( this );
add( five );

ListStyleButtonField six = new ListStyleButtonField( "Directory", caret );
six.setChangeListener( this );
add( six );

ListStyleButtonField seven = new ListStyleButtonField( "Photos", caret );
seven.setChangeListener( this );
add( seven );

ListStyleButtonField eight = new ListStyleButtonField( "Campus Map", caret );
eight.setChangeListener( this );
add( eight );

ListStyleButtonField nine = new ListStyleButtonField( "Weather", caret );
nine.setChangeListener( this );
add( nine );

ListStyleButtonField ten = new ListStyleButtonField( "About", caret );
ten.setChangeListener( this );
add( ten );

_explanation = new UIExampleScreen();
_explanation.setTitle( "Selection" );

LabelField explanationLabel = new LabelField("Detail Screen");
explanationLabel.setPadding(5, 5, 5, 5);
_explanation.add( explanationLabel );


}

public void fieldChanged( Field field, int context )
{

//if statement would go here?


UiApplication.getUiApplication().pushScreen( _explanation );
Dialog.alert("FIELD:" + field);
}


}

Highlighted
Trusted Contributor
Posts: 115
Registered: ‎11-16-2011
My Device: Smartphone Storm 9900
My Carrier: 3

Re: Detecting Selection from AdvancedUI template

Create  private void , and then write statement on your field Change...
 Example :

 

Create :

private void article()
	{
		ArticleScreen article = new ArticleScreen(); //ArticleScreen is name your class which u choose show on next
		UiApplication.getUiApplication().pushScreen(article);
	}

and the next create :
public void fieldChanged(Field field, int context) 
	{
		//action for button main menu
		 if (field==button1){
			article();
		}
        }

 i hope that's help u

New Contributor
Posts: 8
Registered: ‎07-22-2008
My Device: Not Specified

Re: Detecting Selection from AdvancedUI template

I was mostly down the road without success - my problem is that I'm trying to compare field to a string, and I get a "Incompatible operand types Field and String" error.  If I output field, I get the correct label text, such as "Photos", but I don't know how to compare that to make a decision on next steps.

 

Your example says to compare it to "button1", but how do I get "field" to recognize that based on the code provided?

 

Thanks Much!

New Contributor
Posts: 8
Registered: ‎07-22-2008
My Device: Not Specified

Re: Detecting Selection from AdvancedUI template

here is what i'm trying to do w/in the fieldChanged:
if (field.equals("Photos")) {
article();
}
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Detecting Selection from AdvancedUI template

The usual practise, when you are trying to use the fieldChanged method as you are doing here, is to have the Fields as 'global' entities to your entire class.

 

So rather than creating and only being able to reference them within your constructor, you define them in the class itself.

 

Here is a quick sample:

 

public class UIExampleListStyleButtonFieldScreen extends UIExampleScreen implements FieldChangeListener
{
private UIExampleScreen _explanation;

Bitmap caret = Bitmap.getBitmapResource( "chevron_right_black_15x22.png" );

ListStyleButtonField one = new ListStyleButtonField( "News", caret );

ListStyleButtonField two = new ListStyleButtonField( "Events", caret );

public UIExampleListStyleButtonFieldScreen() {

super( NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );

one.setChangeListener( this );
add( one );

two.setChangeListener( this );
add( two );

...

}

public void fieldChanged( Field field, int context )
{

if ( field == one ) {

...

}
UiApplication.getUiApplication().pushScreen( _explanation );
Dialog.alert("FIELD:" + field);
}

}

New Contributor
Posts: 8
Registered: ‎07-22-2008
My Device: Not Specified

Re: Detecting Selection from AdvancedUI template

This works perfectly.  Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!