Get Information From Dialog

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

Get Information From Dialog

Postby aspekt9 » Fri Jul 03, 2009 3:53 am

I have a program that uses a Map View and when they click a menu item it prompts them (in a Dialog box) to enter a name and then press enter. Once they press enter I want to take what was received in the Text Edit in the dialog box and display it in a toast. However, it seems that I just get a blank toast when I try this. Here's some code:

I use getters and setters to accomplish this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public void setText(String text) {
  3.  
  4.                 test = text;
  5.  
  6.         }
  7.  
  8.         public String getText() {
  9.  
  10.                 return test;
  11.  
  12.         }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


My button listener:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.             btn_save = (Button) findViewById(R.id.btn_save);
  2.  
  3.             btn_save.setOnClickListener(new Button.OnClickListener() {
  4.  
  5.                 public void onClick(View v) {
  6.  
  7.                         setText(add_dialog_editText.getText().toString());
  8.  
  9.                         dismiss();
  10.  
  11.                 }
  12.  
  13.             });
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


I then call the dialog in my ItemizedView class:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                                 POIDialog d = new POIDialog(mContext);
  2.  
  3.                                 d.setTitle("Add a POI");
  4.  
  5.                                 d.setContentView(R.layout.adddialog);
  6.  
  7.                                 d.show();
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


But when I use d.getText(), it wont show the value that was entered in the box. Is there a better way to receive entered data in a dialog box?
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Top

Postby aspekt9 » Fri Jul 03, 2009 9:33 pm

I think I know the issue, after I call d.show() to show the dialog, it's not waiting for interaction from the user and it just jumps right down to addLocation() which is why it's not showing up. How can I make the application wait for input received from the user before continuing?
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Postby aspekt9 » Fri Jul 03, 2009 10:49 pm

Okay new update, I got it to display, however it only updates and shows the marker after I click on the screen, any idea why?

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         OnDismissListener mOnDismissListener = new OnDismissListener() {
  2.  
  3.                 @Override
  4.  
  5.                 public void onDismiss(DialogInterface dialog) {
  6.  
  7.                         // TODO Auto-generated method stub
  8.  
  9.                         addLocation(p, "Testing", d.getText());
  10.  
  11.                 }
  12.  
  13.         };
  14.  
  15.        
  16.  
  17.         @Override
  18.  
  19.         public boolean onTouchEvent(MotionEvent event, MapView mapView) {
  20.  
  21.                 if(event.getAction() == MotionEvent.ACTION_DOWN) {
  22.  
  23.                         if (add == true) {
  24.  
  25.                                 p = proj.fromPixels((int)event.getX(), (int)event.getY());
  26.  
  27.                                 d = new POIDialog(mContext);
  28.  
  29.                                 d.setOnDismissListener(mOnDismissListener);
  30.  
  31.                                 d.setTitle("Add a POI");
  32.  
  33.                                 d.setContentView(R.layout.adddialog);
  34.  
  35.                                 d.show();
  36.  
  37.                                 this.add = false;
  38.  
  39.                         }
  40.  
  41.                 }
  42.  
  43.                 return false;
  44.  
  45.         }
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
aspekt9
Junior Developer
Junior Developer
 
Posts: 12
Joined: Tue Feb 24, 2009 5:13 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 17 guests