Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3400584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:54:40+00:00 2026-05-18T04:54:40+00:00

I am working on some example in which i want to drag the image

  • 0

I am working on some example in which i want to drag the image corresponding to touch in Android. Does anybody have an idea about how I can do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T04:54:40+00:00Added an answer on May 18, 2026 at 4:54 am
    public class TouchBall extends Activity {
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        int w=getWindowManager().getDefaultDisplay().getWidth()-25;
        int h=getWindowManager().getDefaultDisplay().getHeight()-25;
    
        BallView ballView=new BallView(this,w,h);
        setContentView(ballView);
    }
    
    
    }
    public class BallView extends SurfaceView implements SurfaceHolder.Callback {
    
        private Bitmap bitmap ;
        private MyThread thread;
        private int x=20,y=20;int width,height;
    
        public BallView(Context context,int w,int h) {
            super(context);
    
            width=w;
            height=h;
            thread=new MyThread(getHolder(),this);
            getHolder().addCallback(this);
            setFocusable(true);
        }
    
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
    
            bitmap =BitmapFactory.decodeResource(getResources(), R.drawable.ball_green);
            canvas.drawColor(Color.BLUE);//To make background 
            canvas.drawBitmap(bitmap,x-(bitmap.getWidth()/2),y-(bitmap.getHeight()/2),null);
    
    
        }
    
        @Override
        public boolean onTouchEvent(MotionEvent event) {
    
            x=(int)event.getX();
            y=(int)event.getY();
    
            if(x<25)
                    x=25;
             if(x> width)   
                    x=width;
             if(y <25)
                    y=25;
             if(y > 405)
                    y=405;      
            return true;
        }
    
        @Override
        public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public void surfaceCreated(SurfaceHolder holder) {
    
            thread.startrun(true);
            thread.start();
    
        }
    
        @Override
        public void surfaceDestroyed(SurfaceHolder holder) {
    
    
            thread.startrun(false);
            thread.stop();
    
        }   
     }
    

    thread:

    public class MyThread extends Thread {
    
    private SurfaceHolder msurfaceHolder;
    private BallView mballView;
    private boolean mrun =false;
    
    public MyThread(SurfaceHolder holder, BallView ballView) {
    
        msurfaceHolder = holder;
        mballView=ballView;
    }
    
    public void startrun(boolean run) {
    
        mrun=run;
    }
    
    @Override
    public void run() {
    
        super.run();
         Canvas canvas;
         while (mrun) {
            canvas=null;
             try {
                 canvas = msurfaceHolder.lockCanvas(null);
                  synchronized (msurfaceHolder) {
                   mballView.onDraw(canvas);
                 }
             } finally {
                     if (canvas != null) {
                     msurfaceHolder.unlockCanvasAndPost(canvas);
                 }
             }
         }
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some textboxes which I want to hide and then show on focus
I have existing C++ lib containing many different classes working together. Some example usage
I have some data which I want to retrieve, but I want to have
I'm working with some example java code for making md5 hashes. One part converts
I'm working through some tutorials and examples of java.util.concurrent package. Usually example authors put
I'm working on a stored proc that executes some dynamic sql. Here's the example
I have been working on some legacy C++ code that uses variable length structures
Edit: solution added. Hi, I currently have some working albeit slow code. It merges
I am working with some legacy code which uses something like this: void store_data(FILE
i got the following regex, which is working on some regex testers out there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.