Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As a newbie myself I've been working with this and it's very simple. Here is some code (maybe there is a better way but this is the way I figured out how to do it):</p> <pre><code>package com.imageviewexample; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageView; public class ImageViewExample extends Activity implements OnClickListener { /** Called when the activity is first created. */ int image_index = 0; private static final int MAX_IMAGE_COUNT = 3; private int[] mImageIds = { R.raw.image1, R.raw.image2, R.raw.image3 }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btnPrevious = (Button)findViewById(R.id.previous_btn); btnPrevious.setOnClickListener(this); Button btnNext = (Button)findViewById(R.id.next_btn); btnNext.setOnClickListener(this); showImage(); } private void showImage() { ImageView imgView = (ImageView) findViewById(R.id.myimage); imgView.setImageResource(mImageIds[image_index]); } public void onClick(View v) { switch (v.getId()) { case (R.id.previous_btn): image_index--; if (image_index == -1) { image_index = MAX_IMAGE_COUNT - 1; } showImage(); break; case (R.id.next_btn): image_index++; if (image_index == MAX_IMAGE_COUNT) { image_index = 0; } showImage(); break; } } } </code></pre> <p>And this is the <code>main.xml</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;Button android:id="@+id/previous_btn" android:layout_width="124dip" android:layout_height="wrap_content" android:text="Previous" /&gt; &lt;Button android:id="@+id/next_btn" android:layout_width="124dip" android:layout_height="wrap_content" android:layout_toRightOf="@+id/previous_btn" android:text="Next" /&gt; &lt;ImageView android:id="@+id/myimage" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/previous_btn" /&gt; &lt;/RelativeLayout&gt; </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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