Hi, the code is working fine now. My code
package com.my.imagechange; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; public class ImageChange extends Activity { private Gallery gallery; private ImageView imgView; private ImageButton btlt,btrt; private Integer[] Imgid= { R.drawable.androidlogo, R.drawable.androids, R.drawable.cool, R.drawable.cupcake2009, R.drawable.donut2009, R.drawable.eclair2009}; int imglength=Imgid.length; int img_position; int img_minus; int img_plus; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); imgView = (ImageView)findViewById(R.id.ImageView01); imgView.setImageResource(Imgid[0]); btlt=(ImageButton)findViewById(R.id.bt1); btrt=(ImageButton)findViewById(R.id.bt2); System.out.println("----->"+imglength +"----->"); btlt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:background="#ffffff"> <ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/androidlogo"/> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" android:layout_gravity="fill_horizontal" > <ImageButton android:id="@+id/bt1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/butleft" android:layout_alignParentLeft="true"> </ImageButton> <ImageButton android:id="@+id/bt2" android:src="@drawable/butright" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true"> </ImageButton> </RelativeLayout> </LinearLayout>
source share