使用imageview [英] Working with imageview
问题描述
我有两个按钮,btn6(有文字)和btn7(无文字)。
I have two buttons, btn6(Has text) and btn7(No text).
btn6.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckButton(btn6, btn3);
CheckButton(btn6, btn5);
}
});
btn7.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckButton(btn7, btn3);
CheckButton(btn7, btn5);
}
});
}
此代码适用于两个按钮,如果我单击按钮文本,该按钮的文本将转到另一个按钮。
This code is for the two buttons where if i click the button with text, the text of that button will go to the other button.
private void CheckButton(final Button btn1, final Button btn2) {
if (btn2.getText().equals(""))
{
btn2.setText(btn1.getText().toString());
btn1.setText("");
}
}
现在,我的问题是,如果我将使用图像(ImageView或ImageButton)而不是文本(按钮)怎么办?这是我的ImageView代码。
Now, My problem is, What if i will use images(ImageView or ImageButton) and not text(button)? This are my codes for ImageView.
iv2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckImageView(iv2, iv1);
CheckImageView(iv2, iv3);
}
});
iv3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
CheckImageView(iv3, iv2);
}
});
private void CheckImageview(final ImageView iv1, final ImageView iv2) {
if ( iv2.getResources().equals(R.drawable.a3))
{
(X) iv2.setImageResource(iv1. "what to put here?" );
iv1.setImageResource(R.drawable.a3);
}
}
Drawable.a3是空白图片
Drawable a1 ,a2不是。
SHOUTING删除 - OriginalGriff [/ edit]
Drawable.a3 is a Blank image
Drawable a1,a2 are not.
[edit]SHOUTING removed - OriginalGriff[/edit]
推荐答案
它无法检索ImageButton或ImageView的图像资源,请改用标签。使用
It is not possible to retrieve image resource of a ImageButton or ImageView, use "tags" instead. Use
setTag()
将图像路径设置为标记,使用
to set image path as tag and
getTag()
按钮检索相同的按钮单击。
to retrieve the same when button is clicked.
这篇关于使用imageview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!