Hi I am new into android development and I am having trouble into this one. I wanted to display the src name of my imageView on a textView when I click a certain Image.
To understand much further here is my hardcode for the image clickListener (hope someone can also help me to improve my coding).
int ctr = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
//DECLARE CLICK LISTENERS ON OBJECTS
ImageView ImageView1 = (ImageView)findViewById(R.id.imageView1);
ImageView1.setOnClickListener(this);
ImageView ImageView2 = (ImageView)findViewById(R.id.imageView2);
ImageView2.setOnClickListener(this);
...
public void onClick(View v) {
//CHANGE TEXT VIEW TEXT BASED ON THE CTR VALUE
TextView TextView1 =(TextView)findViewById(R.id.textView1);
//I WANT TO CHANGE THIS ONE TO DISPLAY SRC INSTEAD OF THE CTR VALUE
TextView1.setText(Integer.toString(ctr));
}
There, instead of displaying the ctr value I wanted to display the src name of whatever image I click between the two images I set. I believe it is possible. Thanks.
You can use below method for get name of resource from it’s id:
For Example of use :
Result will be
icon