Main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/mainImageView"
android:src="@drawable/image_one"
android:layout_width="match_parent"
android:layout_height="450dp" />
<Button
android:text="Change Image"
android:id="@+id/mainButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
package com.kcgroup.iv;
import android.app.*;
import android.os.*;
import android.widget.*;
import android.view.View.*;
import android.view.*;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton(){
final ImageView image=(ImageView)findViewById(R.id.mainImageView);
Button btn=(Button)findViewById(R.id.mainButton);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v){
image.setImageResource(R.drawable.image_two);
}
});
}
}
0 comments:
Post a Comment