I deal with these collections, still doing something wrong.

viewHolder.photo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List<String> images = new ArrayList<>(); Intent intent = new Intent(context, FullScreenViewActivity.class); intent.putExtra("position", position); images.add(imageUploads.get(position).getUrl().toString()); intent.putStringArrayListExtra("items_to_parse", new ArrayList<String>()); context.startActivity(intent); } }); 

By clicking on the photo (I have a list of them), the collection type is created, then we are working with the intent and FullScreenViewActivity.class , after which I will TRY to add from the model the position of the LINK of this photo. Then putStringArrayListExtra again in the collection.

Class FullScreenViewActivity

 public class FullScreenViewActivity extends Activity { private FullScreenImageAdapter adapter; private ViewPager viewPager; ArrayList<String> photo = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fullscreen_view); viewPager = (ViewPager) findViewById(R.id.pager); int position = 0; Intent i = getIntent(); if (i != null) { position = i.getIntExtra("position", 0); photo.addAll(getIntent().getExtras().getStringArrayList("items_to_parse")); } Display display = getWindowManager().getDefaultDisplay(); Point size = new Point(); display.getSize(size); int width = size.x; adapter = new FullScreenImageAdapter(FullScreenViewActivity.this, photo,width); viewPager.setAdapter(adapter); viewPager.setCurrentItem(position); } 

I onClick trying to make changes only in onClick . This activity works correctly (but for other activities). Please tell onClick'e what I'm doing wrong in this onClick'e .

  • You put an empty list of strings in the intent - Yuriy SPb ♦
  • @YuriSPb how can I fill it with values ​​that the user enters. Namely, I would like links (there is a model where getUrl () is, but it has no parameters) - there is also bad luck here, I find it difficult to set values ​​for the parameter. - Inkognito
  • 2
    As far as I understand, you want to transfer images , and transfer the empty (another, again created) list. - post_zeew

1 answer 1

If I understand correctly, you have a list of models, and you need to transfer a list of values ​​from one of the model fields to another one. To do this, you can cycle through the models and form a list of strings like this:

 List<String> strings = new ArrayList<>(); for(ImageUpload imageUpload: imageUploads) { strings.add(imageUpload.getUrl().toString()); } 

Now pass the resulting list of strings to Intent.

 intent.putStringArrayListExtra("items_to_parse", (ArrayList)strings); 
  • thanks for the reaction, only now I added links for example, but for a start I need to set them as an idea to set'it to open them later, if necessary? - Inkognito
  • so understood first SET then ADD? otherwise, I will not be able to add values ​​(links) to pictures. - Inkognito
  • @Inkognito, The add(...) method adds an object to the list, the set(...) method sets an object in the list by position. Using both methods for the same object is meaningless . - post_zeew
  • @post_zeew is good, we added an object (link) to the list, but we don’t know exactly where. That is why you need to first set this object (link) for a specific element (that is, by position). - Inkognito
  • one
    @Inkognito, The add(E element) method adds an object to the end of the list. If you want to add an object at a specific position, you can use the add(int index, E element) method. I really didn’t understand why to know exactly which position the element was added to. - post_zeew