0

In parse i have a class A which has a column (relation) named - view, which relates to class B( contains different images with different object id's).Now what i want to achieve is that : in android i have a activity(A) which has a recycle view which shows all the items of class A. The items are clickable which when clicked brings up the items from class B in parse to activity(B) . Now the issue is we are unable to intent a parse query from activity (A) to activity(B), so that we can display the items of class B in Activity(B).

Is there any different method for this? Any example for this would be of additional help.

EDIT

MainActivity

public class MainActivity extends AppCompatActivity {
ProgressDialog mProgressDialog;
GridAdapter gridAdapter;
RecyclerView recyclerView;
private List<Grid_G_S> grid_list = new ArrayList<>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Get the view from gridview_main.xml
    setContentView(R.layout.activity_main);
    // Execute RemoteDataTask AsyncTask
    new RemoteDataTask().execute();
}

// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        // Create a progressdialog
        mProgressDialog = new ProgressDialog(MainActivity.this);
        // Set progressdialog title
        mProgressDialog.setTitle("Parse.com GridView Tutorial");
        // Set progressdialog message
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        // Show progressdialog
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {
        // Create the array

        grid_list = new ArrayList<>();
        try {
            ParseQuery<ParseObject> query = new ParseQuery<>("CardViewClass");


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

            for (final ParseObject country : object1) {
                // Locate images in flag column
                ParseFile image = (ParseFile) country.get("images");
                ParseRelation<ParseObject> p = country.getRelation("view");

                ParseQuery p2 = p.getQuery();

                String f = image.getUrl();

                Log.i("yji"," "+p2);

                List<ParseObject> oc = p2.find();
                for (ParseObject country2:oc){

                    ParseFile imgs = (ParseFile) country2.get("autoImage");
                    String fr = imgs.getUrl();

                }

                Grid_G_S setter = new Grid_G_S();
                setter.setX(p2);
                setter.setTitles((String) country.get("scrollText1"));
                setter.setImages(f);
                grid_list.add(setter);

            }

            }catch (ParseException e){
            Log.e("err", e.getMessage());
        } catch (com.parse.ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        recyclerView = (RecyclerView) findViewById(R.id.recycler);
        RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(getApplicationContext(),3);
        gridAdapter = new GridAdapter(MainActivity.this, grid_list);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(gridAdapter);


        mProgressDialog.dismiss();

    }  

GridAdapter

public class GridAdapter extends RecyclerView.Adapter {

Context context;
LayoutInflater inflater;
private List<Grid_G_S> grid_g_sList = null;
private ArrayList<Grid_G_S> arraylist;

public GridAdapter(Context context, List<Grid_G_S> grid_list) {

    this.context = context;
    this.grid_g_sList = grid_list;
    inflater = LayoutInflater.from(context);
    this.arraylist = new ArrayList<>();
    this.arraylist.addAll(grid_list);

}


public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView titles;
    ImageView gridImages;
    View mview;

    MyViewHolder(View v) {
        super(v);
        mview = v;
        titles = (TextView) v.findViewById(R.id.grid_single_text);
        gridImages = (ImageView) v.findViewById(R.id.grid_single_image);
    }
}

@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.grid_single_row, parent, false);
    return new MyViewHolder(itemView);
}


@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {

    Grid_G_S item = grid_g_sList.get(position);
    holder.titles.setText(item.getTitles());
    Picasso.with(context)
            .load(grid_g_sList.get(position).getImages())
            .into(holder.gridImages);

    holder.mview.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(context, Secondactivity.class);
            intent.putExtra("image", grid_g_sList.get(position).getImages());
            intent.putExtra("query", String.valueOf(grid_g_sList.get(position).getX()));
            context.startActivity(intent);
        }
    });


}

@Override
public int getItemCount() {
    return grid_g_sList.size();
}

GridGetterSetter

public class Grid_G_S {

String Images;
String Titles;
ParseQuery x;

public String getImages() {
    return Images;
}

public void setImages(String images) {this.Images = images;}

public String getTitles() {
    return Titles;
}

public void setTitles(String titles) {this.Titles = titles;}

public ParseQuery getX() {
    return x;
}

public void setX(ParseQuery x) {this.x = x;}

SecondActivity

public class Secondactivity extends AppCompatActivity {

String q1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_secondactivity);
    new DownloadingTask().execute();

    Intent i = getIntent();
    String images = i.getStringExtra("image");
    q1 = i.getStringExtra("query");
    Log.i("this is ", " " + q1);
}

private class DownloadingTask extends AsyncTask<Void, Void, Void> {
    @Override
    protected Void doInBackground(Void... voids) {

        ParseQuery<ParseObject> query = new ParseQuery<>("CardViewClass");


        try {
            List<ParseObject> object1 = query.find();
            for (final ParseObject country : object1) {
                // Locate images in flag column
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }

}
Manuel
  • 14,274
  • 6
  • 57
  • 130
Saurabh
  • 136
  • 1
  • 1
  • 11
  • pass the array of img.oids from A to B using either 'extra.string' or a bundle. over in B, retreive extra or bundle from Activity A and use the oid's in a parse query to fetch the images ( you will need a media url associated with the img.oid in order to fetch/render the images ). OR you could inline an array of pointers in A.view and use 'include' in the first query to inline all the media info in the response to the first query . – Robert Rowntree Nov 02 '16 at 13:40
  • Hey Robert , Thanks for the reply. My Doubt is still not clear on this .So i have edited and added the activities from the app i am working on . So i have a Grid Adapter Class which has items with On click listener enabled in all items. So now i want that when any item from this Grid Adapter Class is clicked it should fetch all the images from the second class in parse in second activity using recycle view. – Saurabh Nov 02 '16 at 15:12
  • on click in first list , pass as extra strings the array of oids to second activity where you organize those values and do another fetch to parse to get urls and to get the actual media – Robert Rowntree Nov 02 '16 at 19:17

0 Answers0