get data of same objectids from two classes using pointer parse.com

Hashtag class with pointer as hashtagtype class objectid

hashtagtype clas

I have 2 classes “HashTag” and “HashTagType” on parse.com want a query to hit the Hashtag table and Now I want to hit the Hashtag table by navigating through the relationships table. (the relationships table has a column which stores the object IDs of the HashTagtype in the Hashtag class as in Pointer). Hashtag – Objectid, Tags, Pointer(Hashtagtype’s Objectids)

class columns list –

Pointer column has multiple instances of same objected ids of tagtypes

HashtagType – Objectid,Tagtype(no duplicates entries)

need a query that will give me mutilple Tags (atleast 2) for one Tagtype(pointer)

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("HashTagType");
ParseQuery<ParseObject> query2 = new ParseQuery<ParseObject>("HashTag");

ob2 = query.find();
for (ParseObject object : ob2) {

    query2.whereEqualTo("parent", object.getObjectId());
    query2.include("parent");   //the pointer column it must have
    try {
        ob = query2.find(); //this holds the locations Table data
    }

i want to display in list view like

News -hashtagtype 
#breakingnews #echnology  #enterainment ...all tags of **NEWS** 


   Marketing  -hashtagtype 
    #smdata #ux #ecomchat #ecom #ecomerce .... all tags of Marketing

Answer

best way – try to get all the data from parse . while retriving store them on Pojo class(arraylist) and then filter the data using for loop.

 public class ResultClass {

        public String type;
        public String tags;
        public ArrayList<String> listTags = new ArrayList<String>();

    }

    public class class2 {


        public String type;
        public String tag;

    }
    public class class1 {


        public String type;

    }
ParseQuery<ParseObject> hashtag = ParseQuery.getQuery("HashTagType");
        hashtag.whereExists("TypeName");

        hashtag.findInBackground(new FindCallback<ParseObject>()

        {

            public void done(List<ParseObject> NameList, ParseException e)

            {

                if (e == null)

                {
                    if (NameList.size() > 0) {

                        for (int i = 0; i < NameList.size(); i++) {

                            // parsedata map = new parsedata();

                            ParseObject p = NameList.get(i);
                            String name = p.getString("TypeName");
                            Log.e("tyhpe name", "" + name);
                            // String tagid=p.getObjectId();

                            class1 c1 = new class1();
                            c1.type = "" + name;
                            listClass1.add(c1);

                            Hashtagtypes.add(name);

                        }

                        Log.d("hastags", listClass2.toString());

                        ParseQuery<ParseObject> query = ParseQuery
                                .getQuery("HashTag");
                        query.whereExists("Tag");
                        query.orderByAscending("Type");
                        query.setLimit(1000);

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

                            @Override
                            public void done(List<ParseObject> list,
                                    ParseException e) {
                                // TODO Auto-generated method stub

                                if (e == null)

                                {
                                    if (list.size() > 0) {

                                        for (int i = 0; i < list.size(); i++) {

                                            ParseObject p = list.get(i);

                                            String tagid = p.getString("Tag");
                                            String Type = p.getString("Type");

                                            class2 c2 = new class2();

                                            Log.e("hashtype", tagid);
                                            Log.e("hashtag", Type);

                                            c2.type = "" + Type;
                                            c2.tag = "" + tagid;
                                            listClass2.add(c2);



                                        }

                                    }

                                    for (int i = 0; i < listClass1.size(); i++) {
                                        ResultClass result = new ResultClass();
                                        result.type = listClass1.get(i).type;
                                        result.tags = "";
                                        Log.e("size at pos : " + i,
                                                listClass2.size() + "");

                                        for (int j = 0; j < listClass2.size(); j++) {
                                            if (listClass1.get(i).type
                                                    .equals(listClass2.get(j).type)) {
                                                result.listTags.add(listClass2
                                                        .get(j).tag);

                                                result.tags += (listClass2
                                                        .get(j).tag + ",");

                                                // --removing from list for
                                                // performance reason
                                                listClass2.remove(j);

                                            }
                                        }

                                        listResult.add(result);

                                    }

this is not the best way .this will improve api call

 final ArrayList<String> Hashtagtypes = new ArrayList<String>();

                ParseQuery<ParseObject> hashtag = ParseQuery
                        .getQuery("HashTagType");
                hashtag.whereExists("TypeName");

                hashtag.findInBackground(new FindCallback<ParseObject>()

                {

                    public void done(List<ParseObject> NameList, ParseException e)

                    {

                        if (e == null)

                        {
                            if (NameList.size() > 0) {

                                for (int i = 0; i < NameList.size(); i++) {

                                    parsedata map = new parsedata();

                                    ParseObject p = NameList.get(i);
                                    String name = p.getString("TypeName");
                                    // String tagid=p.getObjectId();
                                    map.setHashtag(name);

                                    Hashtagtypes.add(name);

                                     ParseQuery<ParseObject> query =
                                     ParseQuery.getQuery("HashTag");
                                     query.whereEqualTo("Type", name);

                                     query.include("parent");
                                     query.setLimit(2);

                                     try {


                                     List <ParseObject>ob = query.find();

                                     StringBuilder sb = new StringBuilder();

                                     for (ParseObject country : ob) {
                                     // Locate images in flag column


                                     country.get("Tag");
                                     sb.append(country.getString("Tag"));


                                     }
                                     // map.setHashtag(sb.toString());

                                     // totaltaglist.add(map);
                                     tagsdata.add(sb.toString());


                                     }

                                     catch (ParseException e1) {
                                     // TODO Auto-generated catch block
                                     e1.printStackTrace();
                                     }


                                }


                            }

                        }

                    }

                });

Leave a Reply

Your email address will not be published. Required fields are marked *