I'm a new one for android developing. I retrieved a string from hosted database. I want to compare that string and set it as a text according to comparison.
if((dataList.get(position).getname()).equals("5b275526bd5600499cce09ae")) {
holder.txtTitle.setText("denim");
}
else {
holder.txtTitle.setText("shirt");
}
}
The retrieved string is "5b275526bd5600499cce09ae". According to this settext should be "denim". But it display as "shirt".
Then I tried the following one
holder.txtTitle.setText(dataList.get(position).getname());
Then it dispayed as 5b275526bd5600499cce09ae". therefore there is no issues to be seen with the retriving value. I can't figure out with what wrong with this.
Please help me to figure out what's wrong with my code as I'm a new one for Android and Java.
Related
So, I have a school project where I have to parse a json array and put the data in a listview.
Here is the json http://demo4404797.mockable.io/speakers
When I run the app, it shows only 5 elements, cause the fifth throws an exception ("org.json.JSONException: No value for Title", and I know the Title is missing. I just want to know to solve this) and the rest of the array elements arent read.
Here is the code:
I've read in other questions that we can use "ourobject.has("whatwewant")" but my teacher says it has to be done other way. Can you help me please?
The sixth item in the JSON you are using does not have the title key.
Since you are not allowed to use "ourobject.has("whatwewant")".
Just replace your code that uses speaker.getString() with this instead:
String name = speaker.optString("Name", "Name NA");
String image= speaker.optString("Image", "Image NA");
The opt method (there are several optString(), optLong(), optBoolean()...) will return the set value if it is available or it will return what ever value you put as a "fallback" if the key is not available.
Since you can't use the jsonObject.has("tag"), you can also break up the try-catch block.
String name;
try {
name = speaker.getString("name");
} catch (Exception e) {
name = ""; // Occurs when it can't find the tag.
}
Repeat this for every field. Please be intentional using this outside of the classroom.
I am making an android application on crm module of odoo 10 and I want to create quotation in odoo through my application and I am passing this various arguments to ORecordValues and after that I am calling the createRecord().So when I am clicking on save button I am calling python api and python api is giving me this error.
Database fetch misses ids (u'1') and has extra ids (1), may be caused by a type incoherence in a previous request
This is my code for inserting record in odoo.
ORecordValues values = new ORecordValues();
values.put("partner_id",resPartnerArrayList.get(idc).get_id());//parter id
values.put("date_order", binding.qOrderDate.getText().toString());
if(!expDate.isEmpty())
{
values.put("validity_date",
binding.qExpirationDate.getText().toString());
}
if(!paymentTerms.isEmpty())
{
values.put("payment_term_id",paymentTermArrayList.get(idP).get_id());//payment term id
}
if(!binding.qUntaxedAmount.getText().toString().isEmpty())
{
values.put("amount_untaxed",binding.qUntaxedAmount.getText().toString());
}
if(!binding.qTotal.getText().toString().isEmpty())
{
values.put("amount_total", binding.qTotal.getText().toString());
}
if(!binding.qTaxes.getText().toString().isEmpty())
{
values.put("amount_tax", binding.qTaxes.getText().toString());
}
return odoo.createRecord("sale.order", values);
I think you trying to pass unicode value to Many2one field. Perform a type conversion. I think in your case its payment_term_id.
Hope it will help you.
I found the Solution that work for me. I got error because i was passing the String in partner_id which odoo is taking as unicode so i parse the type of it and changed it like this. it worked for me.
values.put("partner_id",resPartnerArrayList.get(idc).get_id())
to
values.put("partner_id", Integer.parseInt
(resPartnerArrayList.get(idc).get_id()));
When I retrieve my data it contains brackets { and unique id such as - JSDHGJDGJJSKA ... I want to make it cleaner and get rid of the brackets for e.g. my output is:
{-JfFQQRYnhiKeuN5ERGX={msg=Monday},-JfFQAhQQWIFAUuV1nD4={msg=this is test}}
I want to get rid of the brackets and the word msg and retrieve just one of the message at random.
I want my output to be if I pick up a random message:
Monday
if I pick up another at random
this is test
Any ideas on how to achieve this will be greatly appreciated.
This will retrieve a random message from the object you've shown in your question.
function getRandomMessage(data) {
if( !data ) { return null; }
var keys = Object.keys(data);
var randomKey = keys[ Math.floor(Math.random()*keys.length) ];
return data[randomKey];
}
Keep in mind that this assumes you have a small number of records. If you start getting into the thousands, you'll need a more robust solution than just grabbing the entire data set.
When I used this I was able to retrieve my data for eg. I save as Book -> title: "The book of death"
here is the code to retrieve the title:Retrieve data-
String title = (String) snapshot.child("title").getValue();
It worked after I used and I didnt used push since push creates its unique ID and its complex for my level to deal with it so I used:Saving data-
Map<String, Object> title= new HashMap<String, Object>();
title.put("title", "This is a working message");
f.child("Book").updateChildren(title);
and everything worked out. I hope it helps everyone who has having these issues. With update children you can use auto increment for your id.
are you getting data in string ? and If you are using string then it is easy , you can use the method of replace eg: yourString.replace("a","b")
I am new to Parse and i am working on a Project that uses Android PARSE Sdk so i was wondering on how can i make a where query with or condition using the android sdk.
I want to make a query like this [Psuedo code]
Select * from employ where employId is ("1","2","3")
I found this on parse documentation, i don't know if it helps or not.
Edit:
This is what i found on PARSE but its not working
String[] id= {"1","2","3"};
query.whereContainedIn("employId ", Arrays.asList(id));
It returns me an empty list but if i query them one by one i get result... Can anyone tell me whats wrong ?
You can use whereContainedIn to select specific rows. See this post you can get more ideas. https://www.parse.com/questions/different-arrays-and-wherecontainedin-for-android.
List<String> employId = new ArrayList<String>();
employId.add("1"); employId.add("2"); employId.add("2");
query.whereContainedIn("employId", employId);
If you are still not clear. check this https://www.parse.com/docs/android_guide#queries
I have found the solution and i must say its pretty lame of PARSE to not mention this anywhere in there documentation.
The problem was that the values that i was using inwhereContainedIn method were of type String but in reality they were pointers to another table's row.
I was trying to get the values using only there ids[as it is displayed on parse] but instead i had to pass the whole object in order to retrieve them. That was the reason on why it was returning empty list.
The thing is Even though it displays IDs [pointer to object in a table] we cant search using only ID's instead we have to use complete Parse objects if we want to search a table based on Specific Object.
I am trying to pass a text from the spinner. Actually the spinner contains the textx which I have fetched from the server side of my application.
So what I am trying to do is that, as soon as I select text from the spinner, I want that string to be passed to the server side. So here i am passing the text to a function which can make a request to the JSP.
Main part of the code(android)
categ = ((TextView) selectedItemView).getText().toString();
postData(categ);
//Remaining section
public void postData(categ)
{
String page="processing_pages/individual_phone_communicator.jsp?rom="+categ;
result = ws.getWebData(page);
if (result != null)
plotData();
else
alerter("null");
}
(It is returning a null value always.But when i am directly running the same query without any parameter and taking the value directly at the JSP page, it shows result)
Now it will move to the JSP.
String hk=request.getParameter("rom");
Now i am running a query like this:
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='"+hk+"'))";
I am expecting it to give back data in the form of json array. But instead it is showing an error. I tried entering the parameter directly from browser even. Sometimes, the page is displaying correct answer with above query. This makes me more confusing. But when i tried with numbers such as 1 or 2 from the eclipse:
String page="processing_pages/individual_phone_communicator.jsp?rom=2"
and modified the query by trying the exact word instead of 'hk' like this
int rom=Integer.parseInt(request.getParameter("romo"));
if(rom==1)
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails";
}
else
{
sqlstatem="select first_name,latitude,longitude from tbluserdetails where user_id=(select user_id from tblindividual_job where jcat_id=(select jcat_id from tbljobcat where job_name='Blood donar'))";
}
it is running correctly. From browser also, it is running correctly when i pass integer as parameter. But i need it to be running by taking a text from the emulator as parameter.
But when I try, like this:
String page="processing_pages/individual_phone_communicator.jsp?rom=Blood donor"
Then also i am getting null as result. What I assume is that, my JSP page is only taking integer parameters, I don't know why it is happening.
I am using net beans for JSP. Kindly find me a solution for this issue. Kindly ignore if the question is childish, as i am just a beginner.
I don't know what the "ws" variable is, but the IP for your local machine (not the phone) in the android emulator is 10.0.2.2. So any URL pointing to a local web app on your machine should start with http://10.0.2.2/...
Mike