I have tried to print a variable value but this is what was printed:
android.support.v7.internal.widget.TintEditText#41fb6428
My code is:
Torre objTorre = new Torre();
objTorre.setLatitude(txtLat.toString());
String torre = objTorre.getLatitude();
System.out.println(torre.toString());
just do this
objTorre.setLatitude(txtLat.getText().toString());
Change the first line to:
objTorre.setLatitude(txtLat.getText().toString());
To get the text from your EditText and not the reference to it.
getLatitude() returns an instance of android.support.v7.internal.widget.TintEditText, which AFAIK is a subclass of EditText.
If you are trying to get at what the user typed into the EditText as a String, call objTorre.getLatitude().getText().toString().
Related
I am new to kotlin and android and I just started getting into using viewbindings.
Im trying to make this locations app and when setting the date through a datepickerdialog, when i try to edit the text of a textview with a binding its giving me errors. Can someone help me?
private fun displaySelectedDate(timestamp : Long){
binding?.etDate?.text = format.format(timestamp)
Change it to
binding?.etDate?.setText(format.format(timestamp))
If you check the docs for EditText, you'll find a setText() method. It takes in a String and a TextView.BufferType. For example:
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("This sets the text.", TextView.BufferType.EDITABLE);
It also inherits TextView's setText(CharSequence) and setText(int) methods, so you can set it just like a regular TextView:
editText.setText("Hello world!");
editText.setText(R.string.hello_world);
//For log in scenario, I just want to enter the userID and password. I tried with different Xpath but still it's not able to identify the box. every-time getting an no such element exception. We are using testNG.
#AndroidFindBy(xpath = "XYZ")
public MobileElement txtUserName;
utils.EnterText(UserNameorMailId,txtUserName);
Different Xpath tried: xyz is placeholder.
//*[#id='username']
//*[#text='Edit Text ; Email Address or Username']
//*[#id='layout_usename']//*[#text='Edit Text ; Email Address or Username']
Error message:
Method threw 'org.openqa.selenium.NoSuchElementException' exception. Cannot evaluate io.appium.java_client.android.AndroidElement$$EnhancerByCGLIB$$34efbdcd.toString()
I am not sure what else I should try and what exactly the issue is...Help is really appreciated ..
What's the exact error you are getting while entering text ? In case you are able to find the element Can you try to use ".//*[#text='Email Address or Username']"
Can you try using AndroidElement instead of MobileElement?
From the docs, I can see that MobileElement is an abstract class which is inherited by AndroidElement class, so using an object of an Abstract class may not work.
MobileElement:
https://appium.github.io/java-client/io/appium/java_client/MobileElement.html
AndroidElement:
https://appium.github.io/java-client/io/appium/java_client/android/AndroidElement.html
Does clicking on the textbox produce the same error? Have you try setValue instead?
I have given this to save data with sharedpreference
so I want to get value to a spinner, here I have given this
SharedPreferences spf = getSharedPreferences("myprfs", Context.MODE_PRIVATE);
String ret = spf.getString("ctyp","");
Here am getting the value to a String, I want to assign a same value to a spinner.
for(int i=0;i<2;i++)
if(ret.equals(spinner.getItemAtPosition(i).toString())){
spinner.setSelection(i);
break;
}
I am getting this error
'java.lang.Object android.widget.Spinner.getItemAtPosition(int)' on a null object reference
Can any one suggest me correct ans..
Your spinner should be null. Set a breakpoint to confirm that. Remember to run in debug mode to make the breakpoint to "break"
Most probably:
not done a findViewById
using ButterKnife and forgot to bind it
If you've done the above, but spinner is still null, in which lifecycle method are you running above code? Maybe you're trying to touch the UI before it's loaded
How do I pass a user variable as a parameter in the Toast object in android studio to display the value of the variable?
Something like this;
Toast.makeText(userVariable,R.id.textField,Toast.LENGTH_SHORT).show();
Thanks
Use getViewById() to get the Text input as a View, cast it to a TextInputView and then once you've done that, you can call getText().toString() and pass this into the toast.
In one of my screen i am using text watcher to check value against a range and for invalid range color of text is being changed.
Now there is one more requirement.
Along with EditText i need to use CheckBox to set completely different range.
The problem i am facing is that changing the checkbox value requires to call afterTextChanged in which i have put all validations for both set of ranges.
So basically my requirement is to update textWatcher anyhow so that afterTextChanged get called after i change value of checkbox.
I get a strange feeling that i am forgetting something very simple here,if so please let me know.
Thanks in advance.
Perhaps move your code from the callback in the textWatcher and put it into another function ie
private void checkRange() {
// do checks here
String color = text.getEditableText().toString();
}
and call this method from your textWatcher and from the listener on the checkbox.