0

So I'm looking for a simple way to display all values of a row with a given objectID. I feel like this should be very straight forward- I've read through the Android help section and maybe I'm looking right past it but I've tried for quite a while and can't get it.

ObID | value 1 | value 2 | value 3


xxxxx | a | b | c

As an example, I want to provide "xxxxx" and then have my listview display "a,b,c". I've tried a query with the following:

@Override
        public void onClick(View v) {
            masterList.removeAll(masterList);
            ParseQuery<ParseObject> columnQuery = new ParseQuery<ParseObject>("MasterTable");

            columnQuery.whereEqualTo("objectId", "vqWGQa6lPT");
            masterListView.setAdapter(adapter);

            columnQuery.findInBackground(new FindCallback <ParseObject> (){

                @Override
                public void done(List<ParseObject> objects, ParseException e) {

                        if(e==null){
                            for( int i = 0; i < objects.size() ; i++) {                

                                Toast.makeText(getApplicationContext(), "Search Successful!", Toast.LENGTH_SHORT).show();

                                //Searches list under the company currently typed into "Company" (AUTOFIND SO STRING SPELLED CORRECTLY!!!)
                                masterList.add(objects.get(i).getString("color"));
                                masterList.add(objects.get(i).getString("companyOne"));

This is the only way I've had luck but it sort of defeats the purpose as to get it to display any of the column names I have to physically type them in.

***************[EDIT ON 2/9/15]****************************************

Here's my table from Parse.com Table

The code Varun provided me returns the following output in my listview:

Color :'green', CompanyName:'g1'

Color:'greenTwo', CompanyName:g2;

Color:'red',CompanyName:r1

Color:'RedTwo',CompanyName:r2

Color:'COLOR',CompanyName:companyOne

So this is querying my table and providing me the data FROM THE COLUMN. What I want is to return the ROW data. So per my table above what I WOULD WANT TO SEE would be the following:

EX:

ObjectID selected: 9jRcxICwgt

ListView relations would display:

'greenTwo' paired with 'color'

'g2' paired with 'companyOne'

'gg2' paired with 'companyTwo'

'ggg2' paired with 'companyThree'

I plan on having boat loads of company so I figured theres an easier way to query the companies without typing in "companyOne", "CompanyTwo", etc... for EVERY company I have in both my table as well as my code. I would just assuming I could input the objectID and then return all row data for everything matching that.

user3803709
  • 107
  • 2
  • 9
  • Try subclassing to write your own class and override toString() method. That way you can just do object.toString() to get all the results in a single string. – varun257 Feb 06 '15 at 06:46
  • http://stackoverflow.com/questions/10734106/how-to-override-tostring-properly-in-java – varun257 Feb 06 '15 at 06:59
  • You lost me there Varun- I don't see how this relates. Could you please elaborate? I'm new to programming btw – user3803709 Feb 07 '15 at 22:56

1 Answers1

0

Create a new class for your object which extends ParseObject.

    @ParseClassName("MasterTable")
    public class MasterTable extends ParseObject{
    // Add public methods to get the value of the object based on key
    public String getColor(){ return getString("color"); }
    // Override toString() method for this object :
    @Override
    public String toString(){
     return "Color: '" + this.getString("color") + "', CompanyName: '" + this.getString("companyOne");
}

Register this class before you do Parse.initialize()

ParseObject.registerSubclass(MasterTable.class)

Write a query that extends your subclass :

 ParseQuery<MasterTable> query = new ParseQuery<>(MasterTable.class);

Now when you get the object from the  Parse,
query.findInBackground(new FindCallback <MasterTable> (){

                @Override
                public void done(List<MasterTable> objects, ParseException e) {

                        if(e==null){
                            for( int i = 0; i < objects.size() ; i++) {                

                                Toast.makeText(getApplicationContext(), "Search Successful!", Toast.LENGTH_SHORT).show();

                                //Searches list under the company currently typed into "Company" (AUTOFIND SO STRING SPELLED CORRECTLY!!!)
                                masterList.add(objects.get(i).toString());
                                masterList.add(objects.get(i).toString());
varun257
  • 296
  • 2
  • 17
  • Varun- Thanks for the response. I think this is taking me down the right path but it still isn't doing what I need it to do. This is returning me the values in the column. See my original post [EDIT] where I will include a table and show you what I am getting returned. – user3803709 Feb 10 '15 at 01:33