Getting numbers from parse.com object in Android - android

I have an object/list coming from parse.com(using parse sdk) and receive both strings and numbers. While I am able to fetch strings I don't know how to fetch numbers.
This works fine for string as driver:
ParseObject u = (ParseObject)scoreList.get(i);
String truckName;
truckName = u.getString("driver").toString();
How do I get the number assuming my "xcor" (assume another property such as "driver") is a number not string.

Maybe I don't understand your question perfectly, but isn't this:
double xcor = u.getDouble("xcor");
just what you need?
(alternatively if you store integer instead of a double you can use int otherVariable = u.getInt("otherVariable");)

Related

Firebase android hashmap integer value turned into Long

changeweek = (Map<String,ArrayList<Integer>>)dataSnapshot.child("week").getValue();
ArrayList<Integer> test = changeweek.get("Monday");
Log.d("changeweek",changeweek.toString());
int j = test.get(2);
I get an error in the last line which is the following:
java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer
at com.example.fake9.tendee.ScheduleActivity$1$1.onDataChange(ScheduleActivity.java:107)
I don't know how this happens since I am storing Arraylist of integers into the hashmap. The following is a picture of the database.
The Firebase SDK internally stores all integer-like number values as Long values, whether or not you want. This helps defend against possibly very large numbers as values.
Your cast to a Map with values of type Integer is overriding that, then causing problems at runtime when the types don't match. You can correct this by simply changing your value type from Integer to Long.
Rather than directly converting long to int, convert long to string using String.valueOf() then we can easily convert string value to int using Integer.parseInt()
So you can go with this,
**
int j = Integer.parseInt(String.valueOf(test.get(2)));
**

String to text field in android app

I have the following data scanned from a pdf417 and need to extract certain text to certain text fields (already created), not sure how to go about this... Data scanned with manatee works plugin and android app using android studio.
All help will be appreciated.
Data that was returned from scan -
%MVL1CC18%0154%4025M003%4025012RP01C%DC62XBGP%NISSAN%SILVER/SILWER%
Each part between the %'s need to go to a text field. I know that I need to make use of String substr=mysourcestring.substring(startIndex,endIndex); but this will work up to the first 2 % signs. How do I continue to the next few?
Thanks.
If you want to split string based on a delimiter, use the following
String delimitter="%";
String[] parts = inputString.split(delimitter);
Why not use String.split()?
In your case it would look something like this:
String[] extractedStrings = mysourcestring.split("%");
You can work on your string by using split method:
String yourString = "%MVL1CC18%0154%4025M003%4025012RP01C%DC62XBGP%NISSAN%SILVER/SILWER%";
String[] split = yourString.split("%");
In this way you will get an array where each item is a substring between two % chars.

I have a database on Parse.com where the values are strings. Is there a way I can split this one attribute into multiple?

I'm creating an app on android that helps users find an apartment around campus by letting you choose the complex, the building inside of that complex, and finally the apartment number. These are done in listviews first starting with a list of the complexes. After this, it opens up a list of the buildings etc.
All of the information is stored in Parse. I have a table called 'Parent' That has all of the complex information stored, and then a 'Children' table that stores the complex, building, a building color (if it has one) and an apartment number.
The app is already created on IOS by a friend of mine and now he wants me to make the android app. When the database was created, it was created in a very messy way. In the 'Children' table, there is a childKey that stores the complex, building, color and apartment number as a string separated only by spaces.
I'm looking for the simplest way to create multiple attributes from this one childKey. Here is an example of what I'm talking about.
Parent Table:
apartmentName = Campus West
apartmentKey = CW
Children Table:
childKey = CW T 10337 ('Parent apartmentKey', 'building', 'apartment#')
latitude = 12.345
longitude = 67.890
I want the Children Table to have:
apartmentKey = CW
building = T
apartment# = 10337
latitude = 12.345
longitude = 67.890
Any ideas?
Could you simply parse through the string data and create a JSONObject that would allow you to grab any specific data you might need for each "Children"?
Parse childKey String
String data = "CW T 10337 ('Parent apartmentKey', 'building', 'apartment#')";
String[] dataList = data.split(" "); // Make String array based on space
Create JSONObject
JSONObject childrenData = new JSONObject();
childrenData.put("apartment_key", dataList[0]);
childrenData.put("building", dataList[1]);
childrenData.put("apartment_no", dataList[2]);
// Not sure what the data in the () is as you do not state its use/where to save it
// Now add the longitude and latitude
childrenData.put("latitude", mLatitude);
childrenData.put("longitude", mLongitude);
You could then pass the JSONObject along and read from it
Read JSONObject
String apartmentKey = childrenData.getString("apartment_key");
String building = childrenData.getString("building");
int apartmentNumber = childrenData.getInt("apartment_no");
Or you could save the JSON object to the device and grab it later on if need be.
This might not be EXACTLY how you tend to implement it but I could see JSONObject being useful as it allows you to store multiple attributes via a key and a value. As long that you are consistent in the database childKey field then this should be fine. If not you could set up some additional logic to catch any special cases.
EDIT:
In case you haven't heard of/used JSONObjects before here is a quick layout of a JSON object:
{
"data": {
"array": [{"value1", 1}, {"value2", 2}]
"string": "value"
"int": 1
}
}
The first part of a JSON object is the key. In "int": 1, the "int" is the key and its value is 1.
Here's a good link about JSON

How to process an array returned by a wsdl?

I am using ksoap2 in order to extract an array of strings from a wsdl based webservice(for an android app). How do I process the returned array? I need those 3-4 lines of code which will let me save and use that returned array in my class. Thanks.
String r = NameArray.columncount("userid", limitstart, loadNumber,loggername);
String temp = r.replaceAll(";\\s", ",").replaceAll("string=", " ")
.replace("anyType{", "").replace(",}", "");
String[] fulname = temp.split(",\\s+");
'NameArray.columncount' is my function which gets the array from the wsdl(don't get confused in that)
step 1-
Here I am getting the array values returned from the wsdl in to a string called 'r'.In this case I am getting an array of numbers
Returned array string r looks like this
r ="anyType{string=10054; string=10055; string=10056; string=10035; string=10052; string=10036; string=10037; string=10038; }"
step 2-
Then creating a String variable called temp where I am removing all the unwanted characters using the replaceAll function.
after removing unwanted characters temp looks like this
temp="10054, 10055, 10056, 10035, 10052, 10036, 10037, 10038"
step3-
Finally created a string array called 'fulname' and split the modified string with ',\s'
Array fulname after split looks like this
fulname = [ 10054, 10055, 10056, 10035, 10052, 10036, 10037, 10038]
This will work fine because all the wsdl array return the same type of string with same unwanted characters
Hope you understood
Good Luck
If you are still on this problem, you can check out this article which explain the whole procedure to parse arrays returned in KSOAP:
http://seesharpgears.blogspot.fr/2010/10/web-service-that-returns-array-of.html
Hope this answer to your question ;)

How to get a string from string.xml in android when constructing name at run time?

In my android app, I have a number of buttons in a grid (basically a 2-D array of components). When long pressing these components I need to display a string to the user, with each array location having different strings.
For an actual app where I am using this, please see :
RIFT Assistant : https://market.android.com/details?id=com.gopalshalu.rift.assistant
In the app, start up a soul tree .
Question
Is there a way to dynamically formulate the name of string, and get the strings value.
Something like…
Int row = 0;
String target_string_name = “”;
for (int col=0;i<1;i++)
{
target_string_name = “teststring_” + row + “_” + col; // we have dynamically created the name
How do we get the actual string value here, using string name in target_string_name variable?
}
How do we get the actual string value here, using string name in target_string_name variable?
Example
String to be displayed when pressing grid location (0,0) - Hello, test string at 0,0
String to be displayed when pressing grid location (0,1) - World!.. test string at 0,1
I have a string.xml file, with the following naming convension:
<string name=’teststring_row_column’>string contents</string>
So, for the above example, the string.xml will look like:
<string name=”teststring_0_0”>Hello, test string at 0,0</string>
<string name=”teststring_0_1”>World!... test string at 0,1</string>
Thanks in advance for your time and responses.
If I understand you correctly, I believe you're looking for getIdentifier().
Here's a demonstration of its use.
I think you might consider making use of setTag() also if you want to associate a particular piece of data with a view. I also started a Rift Calculator (never finished) and for display the spell tooltips (I assume that's what you're doing?) I just associated the tooltip data with the tag for that view.

Categories

Resources