<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/image_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确认" android:layout_gravity="center"/> </LinearLayout>
package com.example.uiwidgettest2; import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.*; public class edittextActivity extends Activity implements View.OnClickListener{ private ImageView iv; private Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.edittext); btn = (Button)findViewById(R.id.button); iv = (ImageView)findViewById(R.id.image_view); btn.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.button: iv.setImageResource(R.drawable.dst); break; default: break; } }}
时间: 2024-09-29 17:33:51