Click here to Skip to main content
15,882,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two buttons, btn6(Has text) and btn7(No text).

VB
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.
VB
private void CheckButton(final Button btn1, final Button btn2) {
       if (btn2.getText().equals(""))
       {
           btn2.setText(btn1.getText().toString());
           btn1.setText("");
       }


}



Now, My problem is, What if i will use images(ImageView or ImageButton) and not text(button)? This are my codes for ImageView.

VB
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 is a Blank image
Drawable a1,a2 are not.

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 17-Dec-13 5:29am
v2
Comments
OriginalGriff 17-Dec-13 11:30am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
JepoyCastle 19-Dec-13 6:30am    
Sorry.

1 solution

It is not possible to retrieve image resource of a ImageButton or ImageView, use "tags" instead. Use
Java
setTag()
to set image path as tag and
Java
getTag()
to retrieve the same when button is clicked.
 
Share this answer
 
Comments
mekalareddy 18-Dec-13 9:56am    
dear,

otherwise simply send constant through parameter and in method use switch case based on constants

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900