1

Ok so I have dynamically created Images. the images are random. what i want to do is to identify what is the string name of the img because i want to compare the string name to something i created dynamically as well. this must be implemented on while on the onTouch. is this possible thanks

I hope i was descriptive enough.

my codes below

    Random rQuestion = new Random();
int iQues = rQuestion.nextInt(numQues - 1)+1;
corrImg = corrAnsIMPID[iQues]; //selectedImg has the string I want to      compare

ArrayList<String> quesList = new ArrayList<>();
quesList.add(corrAnsIMPID[iQues]);
quesList.add(myShuffledArray[rQuestion.nextInt(numQues - 1) + 1]);
quesList.add(myShuffledArray[rQuestion.nextInt(numQues - 1) + 1]);
quesList.add(myShuffledArray[rQuestion.nextInt(numQues - 1) + 1]);
Collections.shuffle(quesList);

String[] ranQues = new String[quesList.size()];
ranQues = quesList.toArray(ranQues);
for(String s : ranQues);  //contains the 4 string name of the img

//set 4 imgs
ImageView newView1 = new ImageView(this);
int id1 = getResources().getIdentifier(ranQues[0], "drawable", getPackageName());
newView1.setImageResource(id1);
//...repeated 4 times

public boolean onTouch (View v, MotionEvent ev)
{

if (mLongClickStartsDrag) return false;

boolean handledHere = false;

final int action = ev.getAction();

// In the situation where a long click is not needed to initiate a drag, simply start on the down event.
if (action == MotionEvent.ACTION_DOWN) {
   handledHere = startDrag (v);


    if (v != selectedImg mSpot2.setDragLayer (null);  //I want to compare if the selected img = corrImg.  this would activate/deactivate the drop zone

}
Mark Ligot
  • 67
  • 7

1 Answers1

1

You can get the name of the resource from its id.

String name = context.getResources().getResourceEntryName(imageResID);

Get The resource id from the imageview again

first set a tag

imageView.setTag(R.drawable.yourDrawable); 

then retrieve from that tag

int resourceID = (int) imageView.getTag();
Sadiq Md Asif
  • 882
  • 6
  • 18
  • 1
    but how do i identify what I clicked to put that context.getResources().getResourceEntryName(imageResID);... – Mark Ligot Jan 10 '17 at 09:31
  • where are you getting images from ? drawable folder or what? – Sadiq Md Asif Jan 10 '17 at 09:54
  • 1
    the img are from a drawable folder generated randomly. I just want to identify what is touched/dragged...the string value of it...basically based on the generated img from the drawable folder, I want to initiate DURING onTouch to see what is currently being selected img..the string name of it – Mark Ligot Jan 10 '17 at 09:57
  • you have the id of image. so set a `onClickListener` to imageView then retrieve from there. – Sadiq Md Asif Jan 10 '17 at 09:59
  • 1
    I can get the string ID of the images no problem...I just dont know how to get the ID of the image selected – Mark Ligot Jan 10 '17 at 10:07
  • glad that helped you :) upvote/accept answers to encourage people for more help. – Sadiq Md Asif Jan 10 '17 at 10:32
  • 1
    i tried i have less than 15 reputation so I cant upvote/accept answer :( – Mark Ligot Jan 10 '17 at 10:37