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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:16:21+00:00 2026-05-25T19:16:21+00:00

public class UnitConverterActivity extends Activity implements OnTouchListener { /** Called when the activity is

  • 0
public class UnitConverterActivity extends Activity implements OnTouchListener {
/** Called when the activity is first created. */
LinearLayout mLinearLayout;

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

    mLinearLayout = new LinearLayout(this);

    ImageView i = new ImageView(this);
    i.setImageResource(R.drawable.mainmenu);
    //i.setAdjustViewBounds(false);
    i.setScaleType(ScaleType.FIT_XY);
    i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    mLinearLayout.addView(i);
    setContentView(mLinearLayout);
    //setContentView(R.layout.main);
}

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
    // TODO Auto-generated method stub
    return false;
}
}

I have used the above method to load an image for the main menu I am trying to create. The image has four areas and each will be used to call a particular function of the app. Now I am trying to implement touch interface on those areas. I know how to define the range of pixels for that purpose but I am at loss on how to implement OnTouchListner on the image. Please help me in this regard.

  • 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-25T19:16:22+00:00Added an answer on May 25, 2026 at 7:16 pm

    If your image was split into four rectangular quarters (say)

    then in onCreate have:

    i.setOnTouchListener(this);
    

    and for your listener, something like this (illustrates the principle only):

    @Override
    public boolean onTouch(View v, MotionEvent mev) {
        int width = v.getWidth();
        int height = v.getHeight();
        float x = mev.getX();
        float y = mev.getY();
        String msg;
        if (x < width / 2) {
            if (y < height / 2)
                msg = "Top left quarter";
            else
                msg = "Bottom left quarter";
    
        } else {
            if (y < height / 2)
                msg = "Top right quarter";
            else
                msg = "Bottom right quarter";
        }
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
        return false;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public class Browser1Activity extends Activity { TextView url; WebView ourBrow; @Override protected void onCreate(Bundle
public class MyActivity extends Activity { /** Called when the activity is first created.
public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);
public class TestConnection extends Activity { /** Called when the activity is first created.
public class SettingsActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /*
public class Offer_Popup extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.offer_popup); //newly
public class HomeActivity extends Activity{ // public ArrayList<User> users1 = new ArrayList<User>(); @Override public
public class Boards : TabActivity { protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.Tab);
public class abc<X extends Z> implements Iterable<X> { protected ArrayList<X> list; public Iterator<X> iterator()
public class CustomEditor : Editor { protected override void Render(HtmlTextWriter writer) { Toolbar topToolbar

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.