Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Picasso GridView - Store URL data in Integer array?
    primarykey
    data
    text
    <p>I'm using Picasso to set a gridview in my Android app. What I wanna do is basically pressing an image in the gridview and go to the detail view.</p> <p>The data was populated in String array like so:</p> <pre><code>static final String[] URLS = { "http://i.imgur.com/file1.jpg", "http://i.imgur.com/file2.jpg", "http://i.imgur.com/file3.jpg", "http://i.imgur.com/file4.jpg" }; </code></pre> <p>In the <code>ImageAdapter</code> those URLS are to be put in an String ArrayList:</p> <pre><code>public class ImageAdapter extends BaseAdapter { private final Context context; private final List&lt;String&gt; urls = new ArrayList&lt;String&gt;(); public ImageAdapter(Context context) { this.context = context; // Ensure we get a different ordering of images on each run. Collections.addAll(urls, Data.URLS); //Collections.shuffle(urls); // Triple up the list. ArrayList&lt;String&gt; copy = new ArrayList&lt;String&gt;(urls); urls.addAll(copy); } @Override public View getView(int position, View convertView, ViewGroup parent) { SquaredImageView view = (SquaredImageView) convertView; if (view == null) { view = new SquaredImageView(context); view.setScaleType(CENTER_CROP); } // Get the image URL for the current position. String url = getItem(position); // Trigger the download of the URL asynchronously into the image view. Picasso.with(context) // .load(url) // .placeholder(R.drawable.placeholder) // .error(R.drawable.error) // .fit() .centerCrop()// .into(view); return view; } @Override public int getCount() { return urls.size(); } @Override public String getItem(int position) { return urls.get(position); } @Override public long getItemId(int position) { return position; } } </code></pre> <p>The problem is when I want to get the Item's ID, it was all stored in String. Here is how my Details View Activity looks like:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.full_image); // get intent data Intent i = getIntent(); // Selected image id int position = i.getExtras().getInt("id"); ImageAdapter ia = new ImageAdapter(this); ImageView iv = (ImageView) findViewById(R.id.full_image_view); iv.setImageResource(ia.getItemId(position)); } </code></pre> <p>The <code>position</code> is from my main activity and it is in Integer. When I want to put the getItemId, <code>setImageResource</code> throws this error:</p> <blockquote> <p>The method setImageResource(int) in the type ImageView is not applicable for the arguments (long)</p> </blockquote> <p>Do you guys have any idea how to fix this?</p> <p><strong>EDIT:</strong> Added ImageAdapter class code</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload