Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your <code>SecondActivity.java</code> items list is <strong>empty</strong>. So, whenever you try to get an item from a position in empty list it will throw error.</p> <p>First of all, try to add few items to the list and also check whether the size of the list is greater than the position which you want to get from the list.</p> <p>Once the above corrections are made, you also have to change the following lines in your <code>SecondActivity</code>,</p> <pre><code>name.setText(items.name); text.setText(items.text); imageView.setImageResource(items.drawableId); </code></pre> <p>to,</p> <pre><code>name.setText(item.getName()); text.setText(item.getText()); imageView.setImageResource(item.getDrawable()); </code></pre> <p>Bcs, you can get the name,text,drawable values for a <strong>single item</strong> and not for whole <strong>items list</strong>.</p> <p><strong>EDIT 1:</strong></p> <pre><code>gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { // Sending image id to SecondActivity Intent i = new Intent(getApplicationContext(), SecondActivity.class); Item item = (Item) items.get(position); // passing index (position of clicked item) i.putExtra("id", position); i.putExtra("Name",item.getName()); i.putExtra("Text",item.getText()); i.putExtra("image",item.getDrawable()); startActivity(i); } }); </code></pre> <p><strong>EDIT 2:</strong></p> <pre><code>i.putExtra("img", R.drawable.ic_launcher); </code></pre> <p><strong>NextActivity</strong></p> <p><code>int img;</code> as <strong>global</strong></p> <pre><code>Intent i = getIntent(); if(i != null) img = i.getIntExtra("img", 0); LinearLayout main_lay = (LinearLayout) findViewById(R.id.main_lay); main_lay.setBackgroundResource(img); </code></pre>
    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.
    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