I want to drop an image over an image and I have a code in which View
is type casted by ImageView
with v.name
'dropped' and this view will display on other ImageView
named 'droptarget' as background but cant happend, plzz tell me a solution. my code is here.:
case DragEvent.ACTION_DROP:
//handle the dragged view being dropped over a target view
View view = (View) event.getLocalState();
//stop displaying the view where it was before it was dragged
view.setVisibility(View.INVISIBLE);
//view dragged item is being dropped on
ImageView dropTarget = (ImageView) v;
//view being dragged and dropped
ImageView dropped = (ImageView) view;
//it give me error in this line
**dropTarget.setBackgroundResource(dropped);**
You should give us more info about the code but anyway I'm going to suggest something.
I think you're calling setBackgroundResource on a null object. So you're mistake is on the next line
ImageView dropTarget = (ImageView) v;
There probably isn't a view called "v". Maybe you should change that?
I believe you are looking for ImageView.setImageResource . You can also set the backgroundImage, but best practice is to use setimageResource.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.