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

  • Home
  • SEARCH
  • 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 8798183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:01:31+00:00 2026-06-14T00:01:31+00:00

public class Sample2 extends Activity { private SampleView sView; private static int displayWidth =

  • 0
public class Sample2 extends Activity  {

private SampleView sView;
private static int displayWidth = 100;    //movement area
private static int displayHeight = 100;
float angle = 0;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    sView = new SampleView(this);
    setContentView(sView);


     }//oncreate

private class SampleView extends View {
    Context con;
    private Rect displayRect = null; //rect we display to
    private int scrollRectX = 0; //current left location of scroll rect
    private int scrollRectY = 0; //current top location of scroll rect
    private float scrollByX = 0; //scroll by amounts
    private float scrollByY = 0;
    private float startX = 0;   //track x from one ACTION_MOVE to the next
    private float startY = 0;   //track y from one ACTION_MOVE to the next
    private int state = 0;


    Bitmap bitmap2;


    public SampleView(Context context) {
        super(context);
        displayRect = new Rect(0, 0, displayWidth, displayHeight);
        }//constructor

  public boolean onTouchEvent(MotionEvent event) {
    float x;
    float y;

       switch (event.getAction()) {

                case MotionEvent.ACTION_DOWN: 
                    //Initial down event location.
                        startX = event.getRawX();
                        startY = event.getRawY()-50;
                       // Log.e("TOUCHED",startY+" "+(scrollRectY+displayHeight));
                        if (((startX>scrollRectX)&(startX<(scrollRectX+displayWidth)))&
                           ((startY>scrollRectY)&(startY<(scrollRectY+displayHeight)))) state = 1;
                        //Log.e("TOUCHED","State "+state);
                        break;
                case MotionEvent.ACTION_MOVE:
                        x = event.getRawX();
                        y = event.getRawY()-50;                            
                        scrollByX = x - startX;
                        scrollByY = y - startY;
                        startX = x; 
                        startY = y;
                        if (state != 0) invalidate(); //move it
                        break;
                case MotionEvent.ACTION_UP:
                        x = event.getRawX();
                        y = event.getRawY()-50;
                        scrollByX = x - startX;
                        scrollByY = y - startY;
                        startX = x; 
                        startY = y;
                        state = 0;
                        invalidate();
                       break;
        }//switch
        return true;
    }//ontouch

protected void onDraw(Canvas canvas) {
   scrollRectX = scrollRectX+(int)scrollByX;
   scrollRectY = scrollRectY+(int)scrollByY;
   displayRect.set(scrollRectX,scrollRectY,scrollRectX+displayWidth,
                   scrollRectY+displayHeight);
   Paint paint = new Paint();
   Bitmap bitmap1 = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
   bitmap2= BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher).copy(Config.RGB_565, true);
   canvas.drawBitmap(bitmap2, null, displayRect, paint);

//TODO: Fill In Methods Etc.
}
}
}

i have used this code….now my question is this how to set separate toast messages for 2 bitmap in android?….if i touch in background rectangle it shows toast message and if i touch on image it shows another toast message by using if condition on ontouchevents….plz any1 can say this….

  • 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-14T00:01:32+00:00Added an answer on June 14, 2026 at 12:01 am

    you can do like this way,

    Demo.java

    public class Demo extends Activity  implements OnClickListener{
     @Override
      protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.demo_layout);
        final LinearLayout lin_layout = (LinearLayout) findViewById(R.id.lin_layout);
        final ImageView img_view = (EditText) findViewById(R.id.img_view);
    
         // call your touch event 
        l_l.setOnClickListener(this);
        imageView1.setOnClickListener(this);
    
     @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.l_l: // if you touch on layout
          // do your task
          Toast.makeText(getApplicationContext(), "You Touch on: Linear_Layout",
              Toast.LENGTH_LONG).show();
          break;
    
        case R.id.imageView1:  // if you touch on Image
          // do your task
          Toast.makeText(getApplicationContext(), "You Touch on : Image ", Toast.LENGTH_LONG)
              .show();
          break;
        default:
          break;
        }
    
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my current code: public class MallMapActivity extends Activity { private final static String
Please find the code sample below: public class Abc extends Activity implements OnClickListener{ private
public class Sample { public static void main(String[] args) { int year = 2012;
I defined a local Service: public class ComService extends Service implements IComService { private
Here's my code package net.sourceforge.jwebunit.sample; import net.sourceforge.jwebunit.WebTestCase; public class JWebUnitSearchExample extends WebTestCase { public
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
Sample code: public class Service1 { public int Service1() { .... } } public
Here is the test code that I am using : public class IOConnectDirect extends
Take this sample class as an example: [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public class BugFixAttribute : System.Attribute
class Sample { public: Sample(){} Sample(const Sample& obj){ cout<<C.C. with 1 argument called<<endl;} Sample(const

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.