In a view controller I have a 2 text boxes (UITextField) and a submit button. The text boxes pop up the ASCII keyboard. The Submit button takes the values from the text boxes and does something with them.
When the keyboard is open, how do I kill it once the submit button is pressed
The keyboard has a Next button, how do I get it to go to the next field.
Using Xamarin Studio 4.0.12
Thank you!
You need to do what incmiko suggested. Here's the code in C#
Part 1.
txtUsername.ShouldReturn = TextFieldShouldReturn;
txtPassword.ShouldReturn = TextFieldShouldReturn;
create a function in your view
private bool TextFieldShouldReturn(UITextField tf)
{
//change the code below as per your validation
if (tf == _txtUsername)
{
_txtPassword.BecomeFirstResponder();
return true;
}
if(tf == _txtPassword)
{
// validate field inputs as per your requirement
tf.ResignFirstResponder();
return true;
}
return true;
}
Just have a try with this ,
It's just a sample,
NSObject keyboardShowObserver;
NSObject keyboardHideObserver;
public override void ViewWillAppear(bool animated) {
base.ViewWillAppear(animated);
keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, (notification) => {
NSValue nsKeyboardBounds = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey);
RectangleF keyboardBounds = nsKeyboardBounds.RectangleFValue;
float height = View.Bounds.Height - keyboardBounds.Height;
if (NavigationController != null && NavigationController.TabBarController != null && NavigationController.TabBarController.TabBar != null) {
// Re-add tab bar height since it is hidden under keyboard but still excluded from View.Bounds.Height.
height += NavigationController.TabBarController.TabBar.Frame.Height;
}
someScrollView.Frame = new RectangleF(someScrollView.Frame.Location, new SizeF(View.Bounds.Width, height));
});
keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, (notification) => {
UIApplication.EnsureUIThread();
someScrollView.Frame = new RectangleF(someScrollView.Frame.Location, View.Bounds.Size);
});
}
public override void ViewDidDisappear(bool animated) {
base.ViewDidDisappear(animated);
if (keyboardShowObserver != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver(keyboardShowObserver);
}
if (keyboardHideObserver != null) {
NSNotificationCenter.DefaultCenter.RemoveObserver(keyboardHideObserver);
}
}
Related
I would like to know the scroll position of ViewCell inside the ListView.
Tried with various ways but always that gives me 0 value.
My intension is to get ViewCell's position in screen. In order to resolve this problem trying to get it's scroll position and then i will add this value to the Y value of ListView object.
Can anybody please help me in this case?
you have to make custom renderer of the ViewCell its kinda tricky to send the positions to pcl then we subscribe to the event in the view here's my code
PCL
public class SAChatViewCell : ViewCell
{
public delegate int[] IntEventHandler(object sender, float[] postion);
public event IntEventHandler OnCellItemLongClicked;
public event EventHandler OnCellItemTouched;
public void InvokeOnCellItemLongClicked(object sender, float[] e)
{
//send the current grid
OnCellItemLongClicked?.Invoke(sender, e);
}
public void InvokeOnCellItemTouched(object sender, EventArgs e)
{
//send the current grid
OnCellItemTouched?.Invoke(sender, e);
}
}
Android Renderer
class SAChatViewCellRenderer : ViewCellRenderer
{
private bool selected;
ClickListener handler = new ClickListener();
static Android.Widget.ListView listView;
Xamarin.Forms.ListView listviewforms;
static SAChatViewCell cellElement;
Android.Views.View cellControl;
protected override Android.Views.View GetCellCore(Cell item, Android.Views.View convertView, Android.Views.ViewGroup parent, Android.Content.Context context)
{
try
{
if (cellControl == null)
{
cellControl = base.GetCellCore(item, convertView, parent, context);
}
cellElement = item as SAChatViewCell;
selected = false;
listviewforms = cellElement.View.Parent.Parent as Xamarin.Forms.ListView;
if (listviewforms == null)
{
return null;
}
if (listviewforms.BackgroundColor.ToAndroid() == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
}
else
{
cellControl.SetBackgroundColor(listviewforms.BackgroundColor.ToAndroid());
}
cellControl.SetOnLongClickListener(handler);
cellControl.SetOnTouchListener(handler);
return cellControl;
}
catch (Exception ex)
{
return null;
}
}
protected override void OnCellPropertyChanged(object sender, PropertyChangedEventArgs args)
{
base.OnCellPropertyChanged(sender, args);
if (args.PropertyName == "IsSelected")
{
// I had to create a property to track the selection because cellCore.Selected is always false.
// Toggle selection
selected = !selected;
var selectedBackground = cellElement.SelectedBackgroundColor.ToAndroid();
if (selected)
{
if (selectedBackground == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
return;
}
cellControl.SetBackgroundColor(selectedBackground);
}
else
{
if (listviewforms.BackgroundColor.ToAndroid() == Color.Transparent.ToAndroid())
{
cellControl.SetBackgroundColor(Color.White.ToAndroid());
}
else
{
cellControl.SetBackgroundColor(listviewforms.BackgroundColor.ToAndroid());
}
}
}
}
internal class ClickListener : Java.Lang.Object, IOnLongClickListener, IOnTouchListener
{
//event priority Touch - LongClick - Click
//NOTE: return true to indicate that we have handled the event and it should stop here;
public bool OnLongClick(Android.Views.View sender)
{
var cellItem = sender as INativeElementView;
var viewCell = sender as Android.Views.View;
float[] location = new float[] { 0, 0 };
Android.Views.View parentRow = (Android.Views.View)viewCell.Parent;
listView = (Android.Widget.ListView)parentRow.Parent;
int position = listView.GetPositionForView(parentRow);
var x = parentRow.Right;
var y = (parentRow.Top - listView.DividerHeight) <= 0 ? parentRow.Bottom : parentRow.Top;
int view_height = parentRow.Height;
location[0] = (x / MainActivity.Current.Resources.DisplayMetrics.Density);
location[1] = y / MainActivity.Current.Resources.DisplayMetrics.Density;
//send current cell
cellElement.InvokeOnCellItemLongClicked((cellItem.Element as ViewCell).View, location);
listView.Scroll += ListView_Scroll;
return true;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (listView != null)
{
listView.Scroll -= ListView_Scroll;
}
}
private void ListView_Scroll(object sender, Android.Widget.AbsListView.ScrollEventArgs e)
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
}
//return false if you have not handled it and/or the event should continue to any other on-click listeners.
public bool OnTouch(Android.Views.View v, MotionEvent e)
{
if (e.Action == MotionEventActions.Down)
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
//cellCore.SetOnTouchListener(this);
}
return false;
}
}
}
}
iOS Renderer
class SAUITableViewCell : UITableViewCell
{
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
}
}
//When you scroll, your cells are created in real time. cells aren't created from scratch, instead iOS just takes a cell that has just left the screen and sends it through
class SAChatViewCellRenderer : ViewCellRenderer, IUIGestureRecognizerDelegate
{
UITableView TV;
SAChatViewCell cellElement;
public IntPtr Handle => new IntPtr();
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
try
{
UITableViewCell cell = base.GetCell(item, reusableCell, tv);
TV = tv;
var uiTapGestureRecognize = new UITapGestureRecognizer(OnClick);
var uiLongPressGestureRecognizer = new UILongPressGestureRecognizer(OnLongClick);
uiLongPressGestureRecognizer.MinimumPressDuration = 0.5;
cell.AddGestureRecognizer(uiTapGestureRecognize);
cell.AddGestureRecognizer(uiLongPressGestureRecognizer);
cellElement = item as SAChatViewCell;
cell.BackgroundColor = UIColor.Clear;
if (cellElement.SelectedBackgroundColor == Color.Transparent)
{
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
else
{
cell.SelectedBackgroundView = new UIView
{
BackgroundColor = cellElement.SelectedBackgroundColor.ToUIColor() ?? default(UIColor)
};
}
return cell;
}
catch (Exception ex)
{
throw ex;
}
}
private void OnLongClick(UILongPressGestureRecognizer arg)
{
//get the current touch coords based on listview
CGPoint coords = arg.LocationInView(TV);
//current cell
if (arg.State != UIGestureRecognizerState.Began)
{
var indexPath = TV.IndexPathForRowAtPoint(coords);
CGRect Rect = TV.RectForRowAtIndexPath(indexPath);
//delete the listview offset
Rect.Offset(-TV.ContentOffset.X, -TV.ContentOffset.Y);
var CurrentViewCell = (arg.View as UIKit.UITableViewCell).Superview;
//Note : xamarin forms cell element MonoTouch creates it's own internal delegate type for UIScrollView so we either override the uiviewtable or trigger the ondisappear event
var cellItem = arg.View as INativeElementView;
(((cellItem.Element as ViewCell).Parent) as ListView).ItemDisappearing += (s, o) =>
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
};
float[] location = new float[] { 0, 0 };
location[0] = (float)Rect.X;
var Y = Rect.Top <= 0 ? Rect.Bottom : Rect.Top;
location[1] = (float)Y;
cellElement.InvokeOnCellItemLongClicked((cellItem.Element as ViewCell).View, location);
}
}
private void OnClick()
{
cellElement.InvokeOnCellItemTouched(cellElement.View, EventArgs.Empty);
}
public void Dispose()
{
throw new NotImplementedException();
}
}
}
I have found a solution,
Problem :
My intension is to get ViewCell's position in screen
Solution :
Step 1 : Keep scrollview inside the Relative layout.
Step 2 : When user click on scroll view's ViewCell, save touch point (X, Y) of relative layout. In Y co-ordinate, add top position of relative layout so you will get touch point relative to whole screen.
Step 3 : When user click on scroll view's ViewCell, call XYZ() method.
Step 4 : Inside XYZ() method, do whatever functionality which required on (X, Y) co-ordinate. (Note : put 300ms delay in doing functionality in XYZ() method, as step-2 required some time in saving
touch points.)
I have the following code which is supposed to show a clickable icon which opens a popup dialog reading out a lengthy note.
this.capacityCommentColumn = this.facilityGrid.addColumn(
p -> {
if (Strings.isNullOrEmpty(p.getCapacityComment())) {
return null;
} else {
return new ThemeResource("img/note.svg");
}
},
new ImageRenderer<>())
.setWidth(80)
.setCaption("Note");
this.facilityGrid.addItemClickListener(new ItemClickListener<MapQueryService.RowResult>() {
#Override
public void itemClick(Grid.ItemClick<MapQueryService.RowResult> event) {
if (event.getColumn() == capacityCommentColumn && !Strings.isNullOrEmpty(event.getItem().getCapacityComment())) {
final NoteWindow noteWindow = new NoteWindow();
noteWindow.txtDescription.setValue("test");
noteWindow.show();
}
}
});
The problem is the code does not respond to clicks on the actual image, only on the outside. You can see this below. Any idea if its possible to make the image clickable?
You need to add a click listener to the Renderer as well. For example:
Grid<Integer> grid = new Grid();
private void addIconColumn() {
ImageRenderer<Integer> renderer = new ImageRenderer<>();
renderer.addClickListener(e -> iconClicked(e.getItem())); // allow clicks on the image
Grid.Column<Integer, ThemeResource> iconColumn = grid.addColumn(i -> new ThemeResource("img/icon.svg"), renderer)
.setCaption("Icon");
grid.addItemClickListener(e -> { // allow clicks on the cell
if (iconColumn.equals(e.getColumn())) {
iconClicked(e.getItem());
}
});
}
private void iconClicked(Integer i) {
... your UI logic here ...
}
You can see a working example here: https://github.com/alejandro-du/community-answers/tree/master/click-image-in-grid
I am making a bubble wrap game. The kind where you press the bubbles to pop them and they unpop after a little bit. it all works fine, the bubbles pop and unpop as planned. There is one issue though. Whenever I click and drag the bubbles still pop. Is there a way to get them not to pop when i click and drag? Here is my code for the touch location.
foreach (TouchLocation tl in touches)
{
if (tl.State == TouchLocationState.Pressed)
{
if (rectangle.Contains((int)tl.Position.X, (int)tl.Position.Y))
{
popLocationX = (int)tl.Position.X;
popLocationY = (int)tl.Position.Y;
}
}
}
Here is what I do, I use this on my main menu but should be able to transfer over.
Have these added in:
MouseState mouse;
public float mouseDelay = 0.01f;
public float mouseTime = 0.0f;
public bool mouseActive = true;
public bool mouseUsed = false;
public string mouseOn = "None";
public Vector2 mouseLocation;
mouse helps find the location of the mouse.
mouseDelay will stop the the repeating when you have the mouse in the pressed position.
mouseTime will say hey, if I am greater than mouseDelay mouse can be used again.
mouseActive will say if it is pressed or not. If mouse is pressed mouseActive is false.
mouseUsed will see if it is ever used. If the mouse is not clicking on anything but the background then it will be false. If true that means it was used to do something.
mouseOn is used in my main menu to say you pressing on options? Make mouseOn = "Options";and go to it.
The mouseLocation holds where the mouse is.
All this in mind putting this all together will help you with your goal of not having the mouse used when it is already pressed.
In update:
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
mouse = Mouse.GetState();
if (this.IsMouseVisible == true)
{
MouseActive(gameTime);
}
base.Update(gameTime);
}
I have if mouse is visible to stop the process from repeating when the mouse is not there (less processing power).
Remember this was made for a main menu if you want to make this for a game you need to mess around with it a little.
void MouseActive(GameTime gameTime)
{
mouseTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
mouse = Mouse.GetState();
mouseLocation = new Vector2(mouse.X, mouse.Y);
switch (gameState)
{
case GameStates.TitleScreen:
break;
case GameStates.Options:
break;
case GameStates.Credits:
break;
}
if (mouseOn != "None")
{
mouseUsed = true;
switch (gameState)
{
case GameStates.TitleScreen:
if (mouseOn == "Play")
{
}
if (mouseOn == "Quit")
this.Exit();
if (mouseOn == "Options")
gameState = GameStates.Options;
if (mouseOn == "Title")
{
}
break;
case GameStates.Options:
break;
case GameStates.Credits:
break;
}
mouseOn = "None";
}
if (mouse.LeftButton == ButtonState.Pressed)
{
mouseTime = 0.0f;
mouseActive = false;
}
if (mouse.LeftButton == ButtonState.Released && mouseTime > mouseDelay)
{
mouseActive = true;
mouseUsed = false;
}
}
All the code from above is going to be in the main class
Here is a class named TitleScreen.cs were I use the images on the TitlesScreen and the mouse from the main class:
You first need to Initialize the thing so add this method in TitleScreen:
Game1 game1;
public void Initialize(Game1 game1)
{
this.game1 = game1;
}
You need to add in an Initializer to the Main class(Game1.cs)
TitleScreen titlescreen;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
titlescreen = new TitleScreen();
}
protected override void Initialize()
{
titlescreen.Initialize(this);
base.Initialize();
}
Then for the final step you add Update to the TitleScreen:
public void Update(GameTime gameTime)
{
MouseState mouse = Mouse.GetState();
if (mouse.LeftButton == ButtonState.Pressed && game1.mouseUsed == false && game1.mouseActive == true)
{
if (play.Contains(mouse.X, mouse.Y))
{
game1.mouseOn = "Play";
game1.mouseUsed = true;
}
else if (title.Contains(mouse.X, mouse.Y))
{
game1.mouseOn = "Title";
game1.mouseUsed = true;
}
else if (options.Contains(mouse.X, mouse.Y))
{
game1.mouseOn = "Options";
game1.mouseUsed = true;
}
else if (quit.Contains(mouse.X, mouse.Y))
{
game1.mouseOn = "Quit";
game1.mouseUsed = true;
}
}
}
You also need to add this to the Update in the main class
titlescreen.Update(gameTime);
I've not worked with touch yet, but the logic should be similar across all input methods.
I would create a variable to store the old TouchLocationState. That way, you can check if the user is clicking and dragging. For example:
//TODO: instantiate this
TouchLocationState oldTLState;
...
// This condition will only be true when the user clicks once, dragging will return false as the oldTLSTate is not released
if (tl.State == TouchLocationState.Pressed && oldTLState.State == TouchLocationState.Released)
{
if (rectangle.Contains((int)tl.Position.X, (int)tl.Position.Y))
{
popLocationX = (int)tl.Position.X;
popLocationY = (int)tl.Position.Y;
}
}
//At the end of the Update() method, update oldTLState with the current state
oldTLState = tl;
I couldn't find anything in the Xamarin documentation about navigating to the next text field in a series of text fields on a form, only a small tutorial on removing the keyboard.
To keep things simple I am using a txtUsername(tag 1) text field and a txtPassword(tag 2) text field. When I implement the following code, it isn't transferring to Xamarin Studio. Does anyone know the way this can be done code in Xamarin Studio, or alternatively if I can transfer the code from XCode to Xamarin Studio.
I am using the following code:
- (BOOL)textFieldShouldReturn:(UITextField *)txtUsername{
NSLog(#"textFieldShouldReturn:");
if (txtUsername.tag == 1) {
UITextField *txtPassword= (UITextField *)[self.view viewWithTag:2];
[txtPassword becomeFirstResponder];
}
else {
[txtUsername resignFirstResponder];
}
return YES;
}
Thanks in advance
I think that the simplest way to do this is using the ShouldReturn method on your UITextFields with the BecomeFirstResponder method. For example, for a login form with Username and Password UITextFields, as follows (in your ViewDidLoad method):
Username = new UITextField();
Username.ReturnKeyType = UIReturnKeyType.Next;
Username.KeyboardType = UIKeyboardType.EmailAddress;
Username.ShouldReturn = (tf) =>
{
Password.BecomeFirstResponder();
return true;
};
View.Add(Username);
Password = new UITextField();
Password.SecureTextEntry = true;
Password.ReturnKeyType = UIReturnKeyType.Go;
Password.ShouldReturn = (tf) =>
{
// Do your login
return true;
};
View.Add(Password);
When you click next when the Username is active, it moves to the Password field. Clicking Go in the password field submits the form.
I wrote a generic solution for every form (not only those with 2 fields).
I´ve got a BaseViewController with these methods:
private UITextField[] formTextfields;
protected void EnableNextKeyForTextFields(UITextField[] fields)
{
formTextfields = fields;
foreach (var field in fields)
{
field.ShouldReturn += ShouldReturn;
}
}
private bool ShouldReturn(UITextField textField)
{
int index = Array.IndexOf(formTextfields, textField);
if (index > -1 && index < formTextfields.Length - 1)
{
formTextfields[index + 1].BecomeFirstResponder();
return true;
}
else if (index == formTextfields.Length - 1)
{
formTextfields[index].ResignFirstResponder();
FormFinished();
}
return false;
}
protected virtual void FormFinished()
{
// this should be implemented on viewControllers using "EnableNextKeyForTextFields"
}
Then, in your view implementation, you just need to pass all your textfields in a single array:
EnableNextKeyForTextFields(new UITextField[] { NameField, SurnameField, EmailField, PasswordField });
When the users clicks "return" when editing the last field of the array, the method "FormFinished" will be called, so you can override it in your implementation:
protected override void FormFinished()
{
(ViewModel as RegisterViewModel).Register(); // or whatever you need to do here
}
I hope this is useful for somebody
You could make use of these functions
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.BecomeFirstResponder
BecomeFirstResponder()
and
http://iosapi.xamarin.com/?link=M%3aMonoTouch.UIKit.UIResponder.ResignFirstResponder
ResignFirstResponder()
According to the documentation you should add the textField Delegate method like this
public virtual bool ShouldReturn (UITextField textField)
{
if (txtUsername.tag == 1) {
UITextField txtPassword = (UITextField)this.view.ViewWithTag(2);
txtPassword.BecomeFirstResponder();
}
else {
txtUsername.ResignFirstResponder();
}
return true;
}
Here's a sample of how to implement in Xamarin.iOS. There may be other simpler ways to do this but I couldn't find any, and this works for me.
I subclassed UITextFieldDelegate to add a custom event handler, then created an instance of it in my view controller code, assigned a lambda expression to the custom event handler so I could access instance variables, and set this delegate instance as the Delegate on my 2 ext fields:
public class LoginTextFieldDelegate : UITextFieldDelegate
{
public EventHandler<UITextField> OnShouldReturn;
public override bool ShouldReturn(UITextField textField)
{
if (OnShouldReturn != null)
{
OnShouldReturn(this, textField);
}
return true;
}
}
Then in my view controller ViewDidLoad method:
var textDelegate = new LoginTextFieldDelegate
{
OnShouldReturn = (sender, textField) =>
{
if (textField.Tag == txtEmailAddress.Tag)
{
txtPassword.BecomeFirstResponder();
}
else if (textField.Tag == txtPassword.Tag)
{
txtPassword.ResignFirstResponder();
}
}
};
txtEmailAddress.Delegate = textDelegate;
txtPassword.Delegate = textDelegate;
Don't forget to set a distinct tag on each UITextField in code / Interface Builder!
Could be easier to use the class available here
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Manage keyboard and tab order
new [] {
usernameField, // Tab order = 0
passwordField, // Tab order = 1
emailField // Tab order = 2
}.InitializeNavigationOnFields();
}
Just call the method passing all the text fields in the order you want them to be navigated through the keyboard.
I recently implemented a solution on a Sign In Screen that handles the question in quite a simple and precise manner.
Not sure if these properties and events existed when the question was first asked but they will help out now for anyone else who needs it.
Entry emailEntry = new Entry()
{
Keyboard = Keyboard.Email,
ReturnType = ReturnType.Next //Changes Return Button on Keyboard to 'Next'
};
emailEntry.Completed += (s, e) => passwordEntry.Focus();
The Completed event fires when the Return Key is pressed. I then set the Focus to my passwordEntry field.
Entry passwordEntry = new Entry()
{
IsPassword = true,
ReturnType = ReturnType.Go //Changes Return Button on Keyboard to 'Next'
};
passwordEntry.Completed += (s, e) => SignInClick(s, e); //SignInClick method handles the sign in functionality
The Completed event for the password entry then initiates the SignInClick method which was previously only handled by a button on the screen.
I am displaying buttons dynamically in my app. When I am determining the number of buttons to be displayed it works fine. However, now I want to change the background color of the button on click and I am able to do that too, but only the label portion changed its color and the rest all is still the same.
So, how can I solve this problem? Here is the code I have so far:
btn = new ButtonField[Global.vec_locdisablecityname.size()];
for(int i=0;i<Global.vec_locdisablecityname.size();i++){
btn[i] = new ButtonField("",ButtonField.CONSUME_CLICK |ButtonField.FOCUSABLE);
btn[i].setLabel((String)Global.vec_locdisablecityname.elementAt(i));
if(Global.flag == true){
Global.flag = false;
Bitmap bmp_backbtnclick=Bitmap.getBitmapResource("bg-btn-location.png");
Background bg_backbtnclick=BackgroundFactory.createBitmapBackground(bmp_backbtnclick);
btn[i].setBackground(bg_backbtnclick);
}
else {
if(Global.selectedbutton == i){
Bitmap bmp_backbtnclick=Bitmap.getBitmapResource("bg-btn-location.png");
Background bg_backbtnclick=BackgroundFactory.createBitmapBackground(bmp_backbtnclick);
btn[i].setBackground(bg_backbtnclick);
}
else {
btn[i].setBackground(null);
}
}
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if ( field instanceof ButtonField ) {
for ( int i = 0; i <= 1; i++ ) {
if ( field == btn[i] ) {
System.out.println("CLicked::::---->>>" +i);
btn[i].setBackground(null);
Global.selectedbutton = i;
selectedcityid = Global.vec_locdisablecitycode.elementAt(i).toString();
System.out.println("value of selected city id:::-->>" +selectedcityid);
selectedcitycodeparse(selectedcityid);
selectedstartloading();
break;
}
else {
btn[i].setBackground(null);
}
}
}
}
};
btn[i].setChangeListener(listener);
hfmbuttons.add(btn[i]);
}