[SOLVED] Calling a dialog from an onTouchEvent

Put your problem here if it does not fit any of the other categories.

[SOLVED] Calling a dialog from an onTouchEvent

Postby ekimia » Sat May 29, 2010 6:59 pm

Im writing a scrollable image app that when the user clicks on a certain part of the screen, a corresponding dialog box pops up. How exactly could i call the dialogbox from an onTouchEvent? Im new to dialog boxes, ive looked through some tutorials for them but just couldnt find out to get them to pop up once the user clicks on the screen. Thanks.
Last edited by ekimia on Mon May 31, 2010 2:47 am, edited 1 time in total.
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Top

Re: Calling a dialog from an onTouchEvent

Postby phix » Sun May 30, 2010 7:27 am

Something along this line:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class DialogTest extends Activity {
  2.     @Override
  3.     public void onCreate(Bundle savedInstanceState) {
  4.         super.onCreate(savedInstanceState);
  5.         setContentView(R.layout.main);
  6.  
  7.         TextView bat = (TextView) findViewById(R.id.temp);
  8.         bat.setText("Click Me");
  9.         final Activity self = this;
  10.         bat.setOnTouchListener(new OnTouchListener() {
  11.             @Override
  12.             public boolean onTouch(View v, MotionEvent event) {
  13.                 if (event.getAction() == MotionEvent.ACTION_DOWN) {
  14.                     Builder builder = new AlertDialog.Builder(self);
  15.                     builder.setTitle("You Touched!");
  16.                     builder.setIcon(R.drawable.icon);
  17.                     builder.setMessage("EventX: " + event.getX() + ". Event Y: " + event.getY());
  18.                                        
  19.                     builder.show();
  20.                 }
  21.                 return true;
  22.             }
  23.         });
  24.     }
  25. }
  26.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Posting questions without code is like going to the doctor and saying "it hurts, fix it."
phix
Master Developer
Master Developer
 
Posts: 230
Joined: Mon Mar 15, 2010 10:37 am

Re: Calling a dialog from an onTouchEvent

Postby ekimia » Sun May 30, 2010 11:31 pm

Thank you sooo much.
ekimia
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sun May 23, 2010 10:13 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests