Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made it running by doing a different approach.</p> <p>MainActivity.java</p> <p>What I did is I pass the R.drawable reference in the intent instead using the string path.</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnArcher = (Button)findViewById(R.id.button_archer); btnArcher.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent intent = new Intent(MainActivity.this,LevelOne.class); intent.putExtra("archer_drawable", R.drawable.archer); startActivity(intent); } }); } </code></pre> <p>On levelOne.java is I used the getIntExtra using the name that I specified in the MainActivity.java to get the R.drawable resource reference of the archer image( you can assign a name whatever you want ). Finally use the integer value that you got from getIntExtra and use it on the the image view by calling the method setImageResource(int resId).</p> <pre><code>ImageView img; int drwResource; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.level_one); //find the ImageView fron level_one.xml img = (ImageView)findViewById(R.id.character_image); drwResource = getIntent().getIntExtra("archer_drawable", -1); img.setImageResource(drwResource); } </code></pre> <p>level_one.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;ImageView android:id="@+id/character_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>I hope this helps. :)</p>
    singulars
    1. This table or related slice is empty.
    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.
    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