0

I want to have an array, and that array is going to be for a spinner. I want the value of that arraylist to be all the values stored in the column "title" in the parse class SpinnerClass. I've looked on the internet but I didn't really understand the other's code and it wa`s really confusing.

Edit: I doubt you guys understand: I have a parse class, and in that class, I have a column named POSTS. It is not a user class. And I want to get ALL the posts from all the rows. So if I have 3 rows, each with posts "red", green", "blue", I want my app to get "red" "green" "blue" from the parse database, and store it in my spinner Thanks for the help

Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
  • Looks like you dont understand: I have a column named "title", in the parse database, and I want to get all the values from that column and store them in an array adapter, so the spinner can get the recieved and put it as its items. – Ali Bdeir Nov 22 '15 at 19:53
  • possible duplicate of http://stackoverflow.com/questions/20599343/how-to-fetch-all-values-for-a-single-key-from-parse-com + http://stackoverflow.com/questions/2784081/android-create-spinner-programmatically-from-array – Nirel Nov 22 '15 at 20:38
  • @Nirel nope, those have NOTHING to do with my question – Ali Bdeir Nov 23 '15 at 07:06

2 Answers2

1

I think you can set up a ParseQueryAdapter to do that.

https://parse.com/tutorials/parse-query-adapter

Add this line to the app's Gradle to be able to import ParseQueryAdapter:

    compile 'com.parse:parseui-widget-android:0.0.1'

Also, so you can get your column:

    // "SpinnerClass" is the class your column is found in parse
    ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>
(this,"SpinnerClass");
    //And to get the column, "Title" is the name of your column
            adapter.setTextKey("Title");
    //And this is to set the spinner adapter
            spinner.setAdapter(adapter);
Ali Bdeir
  • 4,151
  • 10
  • 57
  • 117
nasch
  • 5,330
  • 6
  • 31
  • 52
  • Please give an example, because that links goal isnt direct to mine. I doubt you guys understand: I have a parse class, and in that class, I have a column named POSTS. It is not a user class. And I want to get ALL the posts from all the rows. So if I have 3 rows, each with posts "red", green", "blue", I want my app to get "red" "green" "blue" from the parse database, and store it in my spinner. – Ali Bdeir Nov 23 '15 at 07:10
  • Right, so set up a ParseQueryAdapter and configure it to use only the POSTS column. You'll get that value from every row. – nasch Nov 23 '15 at 14:14
  • I would like that however I get "Unable to resolve symbol "ParseQueryAdapter" " – Ali Bdeir Nov 23 '15 at 17:16
  • Looks like it got moved to Parse UI. I have never used that but here is the page for it: https://github.com/ParsePlatform/ParseUI-Android – nasch Nov 23 '15 at 17:22
0

There is no way to query for columns like this. You could create a cloud code job to fetch things for you (to avoid this bloated query and work on the client), but your best bet would be to rethink your data model.

You need to plan your data model based on your queries; not by any normalization of data. So if getting all the values in this POST column is a query that you will frequently perform, you should create a data model where these values are i.e. stored in an array somewhere for easy retrieval by a simple query. You could have a Spinner object with a posts field that stores an array of those values. This field could for example be populated in an afterSave() event in cloud code.

Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
  • I'm not sure I agree with this. If your data model is based on the queries you expect to run, what happens when the UI is redesigned and now you need different queries? It can be a pain to change the data model in Parse - you cannot rename tables or columns. I think it's best to model the data in the way that best fits what you're representing, and query it as you need to. Better to have some queries that are a little weird or complicated and a sensible data model than the other way around IMO. – nasch Nov 23 '15 at 18:22