Imageview Example i android
}
strings.xml
<?xmlversion="1.0"encoding="utf-8"?>
<resources>
<string name="app_name">ImageView</string>
<string name="action_settings">Settings</string>
<string name="name">See all Images</string>
<string name="next">NEXT</string>
<string name="back">BACK</string>
</resources>
activity_main.xml
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="27dp"
android:text="@string/name"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<Button
android:id="@+id/button_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="19dp"
android:text="@string/back"/>
<Button
android:id="@+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="14dp"
android:layout_marginRight="17dp"
android:text="@string/next"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignLeft="@+id/button_previous"
android:layout_below="@+id/textView1"
android:src="@drawable/kitkat"/>
</RelativeLayout>
MainActivity.java
package
com.wavetronics.task2.imageview;
import
android.app.Activity;
importandroid.opengl.Visibility;
import android.os.Bundle;
import android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.ImageView;
publicclass MainActivity extends Activity {
Button
prevoius,next;
ImageView
image;
@Override
protectedvoid onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
prevoius = (Button)
findViewById(R.id.button_previous);
next = (Button)
findViewById(R.id.button_next);
image = (ImageView)
findViewById(R.id.imageView);
prevoius.setEnabled(false);
prevoius.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
// TODO Auto-generated
method stub
image.setImageResource(R.drawable.kitkat);
prevoius.setEnabled(false);
next.setEnabled(true);
}
});
next.setOnClickListener(new OnClickListener() {
@Override
publicvoid onClick(View v) {
// TODO Auto-generated
method stub
image.setImageResource(R.drawable.lolipopa);
next.setEnabled(false);
prevoius.setEnabled(true);
}
});
No comments:
Post a Comment