0

By using Gestures, can i able to drag like this image ? I mean, have to drag as a tick mark . So for this onClickListener must be used. After it performs,then it should be able to open another screen finally in a display part.

When i use my hand, i mean if i put tick mark , then it should be able to call the particular method.

I wanna write a code by using Gestures and it should be able to perform or drag when i do like this below Image. How does functionalities works here in Gestures and how should i write the code?

How could i do this ? Could anyone suggest me ?See this "Tick" image

Achiever
  • 1,626
  • 10
  • 30
  • 54

1 Answers1

0

I believe you're asking for something along the lines of this question. Here's the source code that was provided by prateek-raj. Incidentally, while the sample checkmark image you provided is lovely, Android doesn't care if your image is an image of a ball, a checkmark, or a squirrel holding a bazooka, so the below code is still applicable.

package com.examples.Touchmoveimage;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

public class Touchmoveimage extends Activity {

    int windowwidth;
    int windowheight;

    private LayoutParams layoutParams ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    windowwidth = getWindowManager().getDefaultDisplay().getWidth();
    windowheight = getWindowManager().getDefaultDisplay().getHeight();
    final ImageView balls = (ImageView)findViewById(R.id.ball);

    balls.setOnTouchListener(new View.OnTouchListener() {

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        LayoutParams layoutParams = (LayoutParams) balls.getLayoutParams();
                        switch(event.getAction())
                        {
                        case MotionEvent.ACTION_DOWN:   
                                                        break;
                        case MotionEvent.ACTION_MOVE:
                                                        int x_cord = (int)event.getRawX();
                                                        int y_cord = (int)event.getRawY();

                                                        if(x_cord>windowwidth){x_cord=windowwidth;}
                                                        if(y_cord>windowheight){y_cord=windowheight;}

                                                        layoutParams.leftMargin = x_cord -25;
                                                        layoutParams.topMargin = y_cord - 75;

                                                        balls.setLayoutParams(layoutParams);
                                                        break;
                        default:
                                                        break;
                        }
                            return true;
                    }
            });
}
}

That addresses most of your question, but not quite all of it. You also asked,

After it performs, then it should be able to open another screen finally in a display part.

The answer is going to likely involve creating an Intent object (with the new activity defined in the constructor and starting it. There's a good tutorial on the subject here. The heart of it (switching activities) is going to be something like this:

Intent k = new Intent("com.example.ActivityYouWantToGoTo");
startActivity(k);

You'll need to go through all the steps associated with creating a new activity. (E.g., don't forget to update the manifest.) To make your code do both (a) dragging the checkbox and (b) switching to the new activity, you'll need to combine the above concepts. You didn't tell us under what circumstances you want the object dragged or the activity switched (e.g., after it's dragged once? When it's dragged to a specific location? etc.), but you're going to want to define those conditions and then call the new activity when they're met.

Community
  • 1
  • 1
Cameron Fredman
  • 1,259
  • 11
  • 24