Using a contentprovider I successfully return a cursor containing the correct data. However, in the onloadfinished method its throwing an exception at simpleCursorAdapter.swapCursor(cursor). Message is IllegalArgumentException: column '_id' does not exist.
No tables in db have such a col name and neither does cursor content. There is nothing in my code with that name.
Any ideas welcome.
Sent from my SAMSUNG-SGH-I337 using xda app-developers app
Just found issue. I should read docs. CursorAdapter must have an _id column in the table it is using. My tables have unique primary keys- like _userid instead of _id to make joins easy as in conventional sql. Now I have to chg all my tables back to _id. Such a pain.
Sent from my SAMSUNG-SGH-I337 using xda app-developers app
Related
Hi,
What's the best approach to load a listview contents from a backend-server (internet)? I mean, I want to populate on-the-go a listview that will retrieve data from a internet server. For example, I want to know all orders from my e-commerce from my app, and I have like 5000 orders in the last week, I won't load this 5000 orders because my app will have a great load time and memory consumation.
My idea is load more when user get close to the last element of list, but I don't know how to do this, and about memory consumation? Is better to continue with the data in memory (when user goes back to upper), or save it on a file-cache (better than memory?) and load when user scroll back to the top?
Thanks,
While the user is the activity you must hold each of the list item in memory anything other than that will cause serious lag in your app
While at other times you may cache them to save resources
Sent from my GT-S5302 using Tapatalk 2
You definetely need ASyncTask here. You can define a class as asynctask, which lets you implement a few methods to use as a background thread. So whenever you wan to load more items you can call this background thread which does not block the UI.
Also, if I remember correctly, you can implement a method which lets you know which list item is at the top of the screen, the total number of items in the listview, and the number of items on the screen.So with this method you can find out whrn you reached the last item in the listview.
I hope this helped a little, at least you got some stuff to google
Sent from my NexusHD2 using xda app-developers app
Ya as he said use a global variable and update it in getView if adapter hence ull know the last loaded view
Sent from my GT-S5302 using Tapatalk 2
i'm writing a questionnaire/survey type app and i need some help with the conceptual design.
i want my app to display 10 random questions selected from about 50 questions. Now I have a class:
public class Question {
public String questionText;
public string answerOptions;
}
What I am confused about is how do I get the 10 questions from the 50 questions?
1)Should the 50 questions be in a SQL database which I "grab" data from and populate my survey as required? In this case how do I a bundle the database with the apk?
2) Initialise 50 Question Objects in the MainActivity and just use them as variables?
I would save them in a normal text file.
Add the 50 questions to an ArrayList. Create a new Array of int with the size of 10 objects.
Add 10 random numbers to it (in the range of 0 - 49, Java: 50 * Math.round()) and before adding one, check whether it is already in the Array. If it is, get another number.
Then get your 10 questions from the list.
I would go for shared preferences rathet it ll save the time
And to be more presice i would suggest using javq.util.Random and call the nextRandom(50) method but remember to check if you havent alread recieved the number
Rest you can follow the above method
Sent from my GT-S5302 using Tapatalk 2
sak-venom1997 said:
I would go for shared preferences rathet it ll save the time
And to be more presice i would suggest using javq.util.Random and call the nextRandom(50) method but remember to check if you havent alread recieved the number
Rest you can follow the above method
Sent from my GT-S5302 using Tapatalk 2
Click to expand...
Click to collapse
Well, if I got him right, he wants to save them and include them into the apk. He asked how to do that. So there is no need for SharedPreferences.
Maybe your method for the random number is better. To be honest, I have never used that method.
nikwen said:
Well, if I got him right, he wants to save them and include them into the apk. He asked how to do that. So there is no need for SharedPreferences.
Maybe your method for the random number is better. To be honest, I have never used that method.
Click to expand...
Click to collapse
I did mean your method.was wrong or something i was just telling an easier method to implement your method in code
Sent from my GT-S5302 using Tapatalk 2
nikwen said:
I would save them in a normal text file.
Add the 50 questions to an ArrayList. Create a new Array of int with the size of 10 objects.
Add 10 random numbers to it (in the range of 0 - 49, Java: 50 * Math.round()) and before adding one, check whether it is already in the Array. If it is, get another number.
Then get your 10 questions from the list.
Click to expand...
Click to collapse
Even though it is only 50 questions now, that would over time be increased to <1000 questions. For what number will a text file be deemed "inefficient" or difficult to work with?
prtbrown said:
Even though it is only 50 questions now, that would over time be increased to <1000 questions. For what number will a text file be deemed "inefficient" or difficult to work with?
Click to expand...
Click to collapse
It would entirely depend on file size and targeted device for instance a device like mine with.300mb ram and 832Mhz proc would crawl to process a 5 mb file while a nexus 4 will do it like a breeze
I would suggest deviding the questions in sets like quesSet1 ,quesSet2 etc
Sent from my GT-S5302 using Tapatalk 2
How do you determine what to "cast" in the code of an Android app? Fixing errors and I'm sort of new to coding Android. For example I get an error at .release and it tells me to add cast to mprinter. What do I cast?
add cast to android code
How do you determine what to "cast" in the code of an Android app? Fixing errors and I'm sort of new to coding Android. For example I get an error at .release and it tells me to add cast to mprinter. What do I cast?
yasra said:
How do you determine what to "cast" in the code of an Android app? Fixing errors and I'm sort of new to coding Android. For example I get an error at .release and it tells me to add cast to mprinter. What do I cast?
Click to expand...
Click to collapse
Dude thats raw java
No offence but you should consider learning java first
Sent from my GT-S5302 using Tapatalk 2
To answer at your very bottom line, Casting (Also known as type conversion) is needed when your data type of the LH side variable isn't the same to that of the RH side.But you cannot use cast everywhere.To better understand this, Start learning java.
add cast
this code is given by my senior and according to him code is working and I need to update the code but first i have to run and understand it properly i.e i have to resolve the issue before updating and understanding.
Well, If you dont know java, or you dont have any past programming experience. Ill try to make this as simple as i can.
A cast is basically, how you convert. For example if you want to convert decimal no. to a simple integer. You should add a cast.
Like:
Code:
float a; // a decimal number.
int b; //an integer
b = (int) a; // converted to decimal..
However, casting is not possible for every conversion. For eg:
You cannot convert a graphics object to an integer.
Hope it helps
Sent from my GT-S6102 using xda app-developers app
Casting is always upward compatible. Eg: int to long for primitive data types.
Secondly you should know the object type to be converted eg from object arraylist etc can contain objects which can be of varied data types.
just like you retrieve db result set from dataype and convert result set to column datatype and store.
Sent from my GT-S5360 using xda app-developers app
Sent from my Q800 using xda app-developers app
When possible, prefer json responses, uses less data transfer than xml and making data processing even faster... that's my personal preference, maybe another developer thinks otherwise...
Sent from my LG-P350 using xda app-developers app
dbarrera said:
When possible, prefer json responses, uses less data transfer than xml and making data processing even faster... that's my personal preference, maybe another developer thinks otherwise...
Sent from my LG-P350 using xda app-developers app
Click to expand...
Click to collapse
Very easy with Google's gson library.
XML might make sense for more complex data structures. But it is difficult to be general here. It's not possible to create precise rules when to prefer XML to others.
I'm currently working on a project which relies heavily on XML parsing, notably to generate UI components.
The XmlPullParser API is really powerful and rather easy to implement.
I'd definitely recommend using JSON if you're parsing from a backend server or even for any online parsing needs, but XML parsing can be useful for creating plugin systems/DSLs, and similar offline use cases.
XML parsing is often used in game apps for multiple levels. It can be used to store coordinates or other information for sprites that will be loaded into a certain level. For parsing large-scale data, XML is a lot faster than JSON in the Android emulator.
Advantages of JSON:
Smaller
Faster
More structural
Easy distinguish between the number 1 and the string "1", strings and booleans.
Easier to represent a null value
Advantages of XML:
Standard ways of expressing the structure of the document: XML schema, DTD, etc
Parsing standards: DOM, SAX, StAX
Hello guys,
These days I've figured it out that my app would look better using some google now-like cards. I've implemented cardsLib and created some layouts for every card I'd need. Everything is working fine except that i can't update their content at onCreate, onStart or onResume and I really need to get some data, interpret it and then populate those Cards wich contains some edit texts.
If I place a button and then try to set some texts works, but i'd need this to be automatically.
I have tried inflating the layout which contains the edit texts, but it just leaves them blank.
Any idea or workaround would be greatly appreciated.
Thank you!
Sent from my Nexus 5 using XDA Free mobile app