How to hide spinner on the basis of text entered in edittext box? - android-edittext

M sorry for wrong English. I want to hide the spinner on the basis of text entered in the edit Text box and not on some click event. This means spinner hiding condition should be checked on the basis of Edit Text value.
Any kind of help will be appreciated.

I have Used TextWatcher class to have a check on the text that is being entered in the edittext. And then have used the method to check ds
private void checkFieldsForEmptyValues()
{
Spinner =(Spinner)findViewById(R.id.site_spinner1);
String s1 = edit1.getText().toString();
String s2 = edit2.getText().toString();
if(s1.equals("admin") && s2.equals("admin"))
{
spinner.setEnabled(false);
}
}

Related

Vaadin TextField's value not available in shortcut listener

I want to read a Vaadin Flow TextField's value when the user presses the Enter key. I can add a ShortcutListener to listen for the keypress, but the value of the TextField is null in the listener even though the TextField is not empty:
TextField textField = new TextField();
Shortcuts.addShortcutListener(UI.getCurrent(), () -> {
String text = texttextField.getValue();
// text doesn't contain the latest text
}, Key.ENTER);
Why is this happening and how can I read the value that the user has entered when the keypress listener is triggered?
The behavior boils down to browser events. While the user may have entered some text into the input element, the value of the TextField is not updated to the server until there's a ValueChange event - even the vaadin-text-field element in the browser doesn't "know" of the text (the value property has not been updated) when the enter keypress event occurs. By default, the value of the text field is only updated when the input loses focus. You can work around the issue by explicitly toggling a blur of the TextField:
// member field in class
boolean shortcutFired = false;
// ...
Shortcuts.addShortcutListener(UI.getCurrent(), () -> {
textField.blur();
shortcutFired = true;
}, Key.ENTER);
and listening to the value change event instead of the shortcut listener:
textField.addValueChangeListener(e -> {
if( shortcutFired ) {
String value = e.getValue();
// do something with the value
shortcutFired = false;
}
}
This approach doesn't work too well if you need to keep track of multiple fields; in that case, you might want to make the TextFields update their values to the server more eagerly by setting their ValueChangeMode to ValueChangeMode.EAGER. The downside of this approach is that it increases the amount of traffic between the browser and the network, as every keypress will trigger a server request.

Setting custom text if TextField is empty

I have a textField called titleTextField in which the user can enter the title of their choice before saving a note. What I want to do is automatically fill this field with the text "Untitled" if the user has left this field blank.
I've tried several solutions, but they either do nothing or set the title always to Untitled even if the user has entered text.
This is the closest I've gotten, but it's still not working right:
if(![self.titleTextField.text isEqual:#""]){
self.titleTextField.text = #"Untitled";
}
My thought was that this would check whether the titleTextField is empty, and if so, it would populate the field with the text "Untitled." I've tried applying this in the viewDidLoad, viewWillAppear, and viewWillDisappear -- I really don't care whether the "Untitled" text is populated when the screen loads or after the user is finished with the page; I just want the end result to be an empty title field saving with the text "Untitled".
Is the coding wrong, or am I just applying it in the wrong place?
Solution as per the way you are looking for is :
if([self.titleTextField.text isEqualToString:#""]){
self.titleTextField.text = #"Untitled";
}
You can also use below :
if([self.titleTextField.text length] == 0){
self.titleTextField.text = #"Untitled";
}

When box is checked make a drop down readonly or uneditable in Rails

I have a drop down box in ruby on rails that allows a date to be entered. And there is a box beside it to indicate that no date will be entered.
When this box is ticked it changes the default value of the date to nil. However the user can still enter a date on the drop down boxes.
When the box is ticked I want the drop down to be readonly or uneditable how can I do this?
EDIT
function BlankOutStartDates() {
if (document.getElementById("service_unknown_start_date").checked == true)
{
document.getElementById("service_start_date_1i").selectedIndex = 0;
document.getElementById("service_start_date_2i").selectedIndex = 0;
document.getElementById("service_start_date_3i").selectedIndex = 0;
}
}
I want to add the addition javascript to make the drop down box read only if the box is ticket
I would actually do this in jQuery. Suppose your checkbox has class "no-date", and your select boxes all of the class "date-select". Then you could do this:
jQuery(".no-date").change(function(){
//Check if the box is checked
if(this.is(':checked')){
jQuery(".date-select").attr("disabled", "true");
} else {
jQuery(".date-select").removeAttr("disabled");
}
});
You'll want to double check "this.is(':checked')" is correct, but I think that will work.
This uses the "disabled" parameter of select tags: http://www.w3schools.com/tags/tag_select.asp

Working with textarea

How can I work with textareas using watin? There is no function like "browser.TextArea(...)".
Is there another name for textareas? I only need to find it and work with rows/cols.
Use the TextField method to access a TextArea.
From the Watin Homepage (modified for this question)
[Test]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
// If there was a TextArea with the name q - the next line would get the TextArea object and assign it to the textField variable.
var textField = browser.TextField(Find.ByName("q"));
// Do what you need to do with the TextArea, for example, get the text from the textArea:
string textAreaText = textField.Value;
}
}
Just came across this myself. I thought I would post a more complete answer for people that are still stumped by this. Just use the GetAttributeValue method on the TextField instance like so:
TextField field = Document.TextField(Find.ByName("comments"));
Assert.AreEqual("10", field.GetAttributeValue("rows"));
Assert.AreEqual("42", field.GetAttributeValue("cols"));

text field in a dialog box on a BlackBerry

I want to create an empty dialog box with a text field inside. When the user enters data inside the box he must be redirected to another screen. I want the Dialog box to come up without any statements but must include a textfield
That should be doable with a PopupScreen, EditField and maybe a ButtonField so the user can let you know he/she is done entering data.
Just create standard OK dialog and then add an EditField to it.
BasicEditField inputField = new BasicEditField();
Dialog d = new Dialog(Dialog.D_OK_CANCEL, "Enter your Username:", Dialog.OK, null, Dialog.DEFAULT_CLOSE);
d.add(inputField);
int i = d.doModal();
if (i == Dialog.OK) {
Dialog.inform("Your Username is : " + inputField.getText());
}
Here's a complete tutorial

Resources