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 8804809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:42:07+00:00 2026-06-14T01:42:07+00:00

I have multiple views being dragged around, each representing an emotion. the idea is

  • 0

I have multiple views being dragged around, each representing an emotion. the idea is to have each view send an entry to a database that varies based on what view is dragged.

the views are created here:

_root = (ViewGroup)findViewById(R.id.root);

_view = new ImageView(this);
_view.setImageResource(R.drawable.smile); 
_view2 = new ImageView(this);
_view2.setImageResource(R.drawable.frown); 



RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 50);
layoutParams.leftMargin = 250;
layoutParams.topMargin = 250;
layoutParams.bottomMargin = -250;
layoutParams.rightMargin = -250;
_view.setLayoutParams(layoutParams);
_view.setOnTouchListener(this);

RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(150, 50);
layoutParams2.leftMargin = 250;
layoutParams2.topMargin = 500;
layoutParams2.bottomMargin = -250;
layoutParams2.rightMargin = -250;
_view2.setLayoutParams(layoutParams2);
_view2.setOnTouchListener(this);
_root.addView(_view);
_root.addView(_view2);

}

And the movement and drag is defined here:

public boolean onTouch(View view, MotionEvent event) {
    final int X = (int) event.getRawX();
    final int Y = (int) event.getRawY();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_DOWN:
            RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            _xDelta = X - lParams.leftMargin;
            _yDelta = Y - lParams.topMargin;
            break;
        case MotionEvent.ACTION_UP:  
            Intent intent = new Intent(this, Exit_Activity.class);
         startActivity(intent);
            break;
        case MotionEvent.ACTION_POINTER_DOWN:
            break;
        case MotionEvent.ACTION_POINTER_UP:
            break;
        case MotionEvent.ACTION_MOVE:
            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
            layoutParams.leftMargin = X - _xDelta;
            layoutParams.topMargin = Y - _yDelta;
            layoutParams.rightMargin = -250;
            layoutParams.bottomMargin = -250;
            view.setLayoutParams(layoutParams);
            break;
    }
    _root.invalidate();
    return true;
}

}

As you can see, ACTION_UP currently sends the user to the next activity, regardless of which view is dragged. What’s the best way to have the app differentiate between views?

  • 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-06-14T01:42:08+00:00Added an answer on June 14, 2026 at 1:42 am

    Set ID for the individual view. Retrieve the ID when the view is clicked. ID is unique identity for each view. To set the id:

    view.setId(x);
    

    When clicked, retrieve the id:

    id = view.getId();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view that has multiple views inside it, and an image presentation
I have a ListView with each item being a custom layout with multiple Views
I have a MVVM application that contains multiple views with some complex IsReadOnly rules
I have multiple textfields on my view, and each time a textfield is taped
I currently have an application that is storing around 10 variables per android view
My controller is decorated with [HandleError] and [HandleError(ExceptionType=typeof(CustomException), View=CustomView)] . I have views that
I have multiple imageViews that I drag around in my app. I have added
In my iPad Application I have multiple views on a screen. What I want
Is it considered bad practice to have multiple views for same URL in MVC,
I have a very large script which is creating multiple views. In a number

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.