11-29-2011 08:38 PM
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);
}
}
Solved! Go to Solution.
11-30-2011 04:20 AM
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(articl e);
}
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
11-30-2011 06:43 PM
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!
11-30-2011 06:51 PM
11-30-2011 08:04 PM
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);
}
}
11-30-2011 09:23 PM
This works perfectly. Thank you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!