[Q] Convert Editable to String? - Android Software Development

I am making a dialog box that the user can enter text into as input. I am using this sample code http://www.tutorials-android.com/learn/How_to_prompt_user_input_with_an_AlertDialog.rhtml
In that example it uses "String value = input.getText();" but the Eclipse says it doesn't work and makes me change 'value' to type 'Editable'. How do I convert it back into a string?
Thanks in advance

hyperbyteX said:
I am making a dialog box that the user can enter text into as input. I am using this sample code http://www.tutorials-android.com/learn/How_to_prompt_user_input_with_an_AlertDialog.rhtml
In that example it uses "String value = input.getText();" but the Eclipse says it doesn't work and makes me change 'value' to type 'Editable'. How do I convert it back into a string?
Thanks in advance
Click to expand...
Click to collapse
Try using "String value = input.getText().toString();"

thanks I got it!

Related

[Q] SQLITE Issue

Hello All,
I am working on learning about SQLITE and I came across a a problem I can't seem to find a solution to.
I have the following code to create a table and then insert some info. The problem is that every time I refresh I adds another insert. I been searching around and I have tried several of methods but can't seem to make it work:
Code:
db = openDatabase(shortName, version, displayName, maxSize);
db.transaction(
function(transaction) {
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS info ' +
' (name VARCHAR, lastname VARCHAR);'
);
}
);
db.transaction(
function(transaction) {
transaction.executeSql(
'INSERT OR REPLACE INTO info (name, lastname) VALUES ("Jose", "Lopez");'
);
}
);
});
What am I missing? Every where I search it said that if I use "NSERT OR REPLACE INTO" it would insert if it doesn't exist but if it does it would replace the info. It just keeps adding a new row. Any suggestions?
Thank you in advance.
Not sure, but since there's no index on the table to force unique rows, it'll just keep inserting a new row.
Sent from my PC36100 using XDA App
mixerman826 said:
Not sure, but since there's no index on the table to force unique rows, it'll just keep inserting a new row.
Sent from my PC36100 using XDA App
Click to expand...
Click to collapse
I search and read about it so I added "id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT" and also learn about "TEXT UNIQUE" and added that as well. So it looks like this:
Code:
transaction.executeSql(
'CREATE TABLE IF NOT EXISTS info ' +
' (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, ' +
' name TEXT UNIQUE, lastname TEXT UNIQUE);'
);
it worked like a charm! Thanks for pointing me into the direction. Thank you so much!

Quick variable type question.

I have an EditText object (et_travel) on my screen that's asking for miles traveled. I grab that data like this:
Code:
float travel = Float.parseFloat(et_travel.getText().toString());
if(travel > 40000){
I just discover that if someone puts 40000 in the EditText, everything works fine, but if they put 40,000 (adding a comma to the number), I force close on the float travel = ...statement.
How can I evaluate the number without having a problem from the user adding a comma?
you should parse the string before you run it through Float.parseFloat() so that there are no bad characters in the string. use some of the String methods to find and remove bad characters.
Also that parsefloat method probably throws some sort of exception. You could catch it and let your user know that there value is invalid and to try again
Sent from my Desire HD using XDA App
Set the properties on the edittext so it accepts numbers only.
android:inputtype="numberDecimal|numberSigned"
________________________________
http://ron-droid.blogspot.com

How to call ATT service numbers (numbers ending with #) in the app

Hi all,
I need a feature in my app to call AT&T and check the balance or minute usage. For example, to check how many minutes I have used, normally I should dial *MIN# (*646#) on my phone, and then I will get a text message.
I use the following simple way to make the phone call:
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:*646#"));
However in my app it seems the ending "#" is always ignored and the number my app dials is always *646, which goes nowhere.
Can anyone let me know how I can get to call the number with its ending character "#"?
Thanks,
Lik
Maybe try a backslash before the pound sign.
Code:
callIntent.setData(Uri.parse("tel:*646\#"));
I did try that but it didn't work.
What about the "*"? I'm guessing that Uri.parse() is trying to "parse" the string and that some character or another is being interpreted as a control character by the "parse" function.
Edit:
OK, I just did a search on URI encoding and found this:
http://www.tutorialspoint.com/html/html_url_encoding.htm
and according to this:
http://developer.android.com/reference/android/net/Uri.html
a "#" sign is interpreted as a fragment delimiter.
The first ref says to use "%23" to encode the # char so try this:
Code:
callIntent.setData(Uri.parse("tel:*646%23"));
That works. Thanks.

[Q] How to convert ASCII character to decimal number in Android?

Hi!
I'm working on an Android app. I have a TextView which contains an ASCII character. This character changes every 2 hours. I need to be able to read this character and convert it to decimal number, and then write it to an another TextView. So let's say the character is "[" and it's decimal value is 91. 2 hours later this character changes to "U" and it's decimal value is 85.
Can anyone help me what kind of code should I use in my app to be able to convert ASCII character to decimal number?
Thanks for helping.
adamhala007 said:
Hi!
I'm working on an Android app. I have a TextView which contains an ASCII character. This character changes every 2 hours. I need to be able to read this character and convert it to decimal number, and then write it to an another TextView. So let's say the character is "[" and it's decimal value is 91. 2 hours later this character changes to "U" and it's decimal value is 85.
Can anyone help me what kind of code should I use in my app to be able to convert ASCII character to decimal number?
Thanks for helping.
Click to expand...
Click to collapse
You can use an implicite cast:
Code:
char c = '[';
int decimal = c; //the decimal value
//for output:
Log.d("Decimal value", "" + decimal);

APK development help - encoding characters from a string

I am trying to swap out characters from one string to those in another (like the simple alphabetic offset code people used as kids), the code I am using is
public void convertMe(){
//lets convert the text
rInput = etrInput.getText().toString();
//lets extract the input characters to a chararray
char[] inputArray = rInput.toCharArray();
//lets get the numbers and make them a string
rNumbers = etrNumbers.getText().toString();
//lets extract them and place them in an chararray
char[] numbersArray = rNumbers.toCharArray();
for (int i=0; i<inputArray.length; i++){
rResult = rNumbers.replace(numbersArray, inputArray);
}
}
Clarification of the behaviour of my code above:
If the string rInput is smaller than the rNumbers array then the app crashes. If not then the only character that is encoded is the last character looped through the array.
I would like to be able to 'encode' all characters in the array, and also be able to encode any number of characters, not be limited to matching the length of the numbersArray.
How can I deal with the arrays of different lengths to substitute the values?
rInput must be 10character word
rNumbers can be any length string but only containing numbers.
The result should be that the numbers are "coded" in simple terms using the letters from the rInput charArray:
ACHROMATIC
0123456789
So encoding 5501 should give the answer MMAC, or 5512345 should give MMCHROM.
User enters a 10character word with no 2 characters the same (like the example achromatic)
User can then enter a series of numbers. (5501)
The substitution should then take the int value of each digit entered by the user, look up that value from the first word and substitute that character:
The fifth letter in the word achromatic is m (assuming you count from 0). The result of 5501 being substituted should be MMAC.
Thanks;
Andy
Anyone able to give me a steer on how i should adjust my code for this to work?

Categories

Resources