我只想设置按钮的图像以在单击时更改。例如,如果我想点击按钮 A 它会改变。如果我单击按钮 B,它的图像将改变,按钮 A 的图像将恢复。我怎样才能做到这一点?我非常需要这方面的帮助。
package com.example.mobile_nurse;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.ImageButton;
public class Posture_1 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_posture_1);
Back();
_1minute();
_15minute();
}
private void _15minute() {
ImageButton Button1 = (ImageButton) findViewById(R.id.imageButton3);
ImageButton Button4 = (ImageButton) findViewById(R.id.imageButton4);
View.OnClickListener myListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Button1.setBackgroundResource(R.drawable.posms1_button1_null);
Button4.setBackgroundResource(R.drawable.posms1_button_a);
}
};
Button1.setOnClickListener(myListener);
}
private void _1minute() {
ImageButton Button1 = (ImageButton) findViewById(R.id.imageButton3);
ImageButton Button4 = (ImageButton) findViewById(R.id.imageButton4);
View.OnClickListener myListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Button1.setBackgroundResource(R.drawable.posms1_button1);
Button4.setBackgroundResource(R.drawable.posms1_button_a_null);
}
};
Button1.setOnClickListener(myListener);
}
private void Back() {
ImageButton Button = (ImageButton) findViewById(R.id.imageButton1);
View.OnClickListener myListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
};
Button.setOnClickListener(myListener);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.posture_1, menu);
return true;
}
}