Android automatic input to text field of messaging - android

I have created an app using jelly bean version 4.2, the issue is that I have to created an input field on submission of that values a message should be sent. I want to know how this input values can be automatically put in the text field of the message.
Can anyone please help me out in sorting this issues.

I am presuming(as no additional info is available) that you want to display some message, like a toast, which should contain the value of your text field.
You can use like:
EditText text = (EditText)findViewById(R.id.textFieldID);
String value = text.getText().toString();
Then use this string as message in your toast or pass it as an argument!!
Hope this helps!!

Related

How to set string on Spinner Prompt programmatically?

How to set the string values on spinner prompt?
The process how I am doing is:
I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.
Later, I am trying to set the string value in Spinner prompt
SP_gender is called as Spinner here. In String gender1, I have texts called as "male"
String gender1 = i.getStringExtra("bundle_CusGender");
SP_gender.setPrompt(gender1);
System.out.println("Check bundle_CusGender = : " + gender1);
When I try to print this, I am getting a value as male
System.out: Check bundle_CusGender = : male
How should I set the single text in spinner Android?
Firstly the setPrompt() methods documentation states:
Sets the prompt to display when the dialog is shown.
Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.
Set hint text to be displayed to the user. This should provide
a description of the choice being made.
So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)
For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.

(Appium) Using sendKeys to write a number in an input field which already has a +91 hardcoded as a prefix, does not enter the number correctly

It selects and copies the number which I am sending and sometimes enters it before the +91 which eventually results in an error.
Below is the code I am using to send a number in to the number input field.
WebElement number = driver.findElement(By.id("com.ulink.agrostar.debug:id/edt_enter_mobileNumber"));
number.sendKeys("7976358798");
You have to first check whether your edit field consist of predefined field like
"+91", If it is there you can override text like these.
if(element.getText().trim().equals("+91")) {
number.clear();
}
number.sendKeys("+91" + "7976358798");
It should work please check.

Run time errors in eclipse android application [unfortunately application has stopped]

I am facing an issue in my app ,when I click the button inside my app it gives the error
(unfortunately application has stopped),
and these are problems in Logcat :
please help me out ,what exactly is the issue ?
i solved it , thnx guys
You have an editText which accepts inputs other than numbers also.
I assume you are trying to convert the value in the editText to an Integer using
Integer.parseInt ((String) EditText.getText());
Either restrict the input in the editText to numbers only.
Or, Handle Number format Exception gracefully with an appropriate error message!
It looks like you're trying to parse a value starting "android.widget.EditText" - which suggests you may have code like this:
int x = Integer.parseInt(editText.toString());
That's not going to get the text of the EditText - for that, you want to call getText():
int x = Integer.parseInt(editText.getText().toString());

Checking for input with space

I've made an offline currency convertor that gets the users input in the EditText section using a TextWatcher and returns the required ouptut from methods...and I"ve made it an a way that the user cannot insert a "null" value in the EditText section and then press the convert button by using euro.getText !==null for example.But I don't know how to proceed when the user leaves some space between the input,for instance 29 50.This will make my program to crash.My question what should I use to check for an input with space in order to avoid a program crash?Thank you.
Your program crashes with number format exception. You can do so:
try{
double value = Double.parseDouble(editText.getText().toString());
} catch(NumberFormatException ex){
Log.e(TAG, "improper number format");
//show some dialog saying what's the format that should be entered
}
You can also go with a regex:
String editTextValue = editText.getText().toString();
if(editTextValue.matches("\\d+\\.\\d+")){
double value = Double.parseDouble(editTextValue);
} else{
//show dialog saying what should be the format.
}
This is actually quite easy.
Does your app accept numbers with a comma or a dot? Either way, you can simply replace the String by the symbol of you choice by using the following:
String unspaced = edittext.getText().toString().replace(' ', '.'); // or , depending on what your app uses

Retrieving entered text in field (android help)

I have this code for a username field for an Android app. I would like to validate the field to see if it is empty. Here is my code:
View a = findViewById(R.id.authentication);
(a.toString().equals(""))
I am guessing that you cannot use view to get the data entered by the user. What would be the best way to see if these fields are empty?
a.toString() does not do what you think it does.
Use TextView a = (TextView)findViewById(R.id.authentication); (a.getText().equals(""))

Categories

Resources