Get values from a dialog

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Get values from a dialog

Postby puxdroid » Tue Dec 22, 2009 5:51 pm

Hello!
I need launch a dialog like this:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <?xml version="1.0" encoding="utf-8"?>
  3.  
  4. <LinearLayout
  5.  
  6. android:id="@+id/widget28"
  7.  
  8. android:layout_width="fill_parent"
  9.  
  10. android:layout_height="fill_parent"
  11.  
  12. android:orientation="vertical"
  13.  
  14. xmlns:android="http://schemas.android.com/apk/res/android"
  15.  
  16. >
  17.  
  18. <TextView
  19.  
  20. android:id="@+id/nameMessage"
  21.  
  22. android:layout_width="fill_parent"
  23.  
  24. android:layout_height="wrap_content"
  25.  
  26. android:text="Enter Name:"
  27.  
  28. >
  29.  
  30. </TextView>
  31.  
  32. <EditText
  33.  
  34. android:id="@+id/nameEditText"
  35.  
  36. android:layout_width="fill_parent"
  37.  
  38. android:layout_height="wrap_content"
  39.  
  40. android:textSize="18sp"
  41.  
  42. >
  43.  
  44. </EditText>
  45.  
  46. <LinearLayout
  47.  
  48. android:id="@+id/buttonLayout"
  49.  
  50. android:layout_width="fill_parent"
  51.  
  52. android:layout_height="wrap_content"
  53.  
  54. android:layout_gravity="center_horizontal"
  55.  
  56. >
  57.  
  58. <Button
  59.  
  60. android:id="@+id/okButton"
  61.  
  62. android:layout_width="wrap_content"
  63.  
  64. android:layout_height="wrap_content"
  65.  
  66. android:text="OK"
  67.  
  68. >
  69.  
  70. </Button>
  71.  
  72. <Button
  73.  
  74. android:id="@+id/cancelButton"
  75.  
  76. android:layout_width="wrap_content"
  77.  
  78. android:layout_height="wrap_content"
  79.  
  80. android:text="Cancel"
  81.  
  82. >
  83.  
  84. </Button>
  85.  
  86. </LinearLayout>
  87.  
  88. </LinearLayout>
  89.  
  90.  
Parsed in 0.004 seconds, using GeSHi 1.0.8.4


An I have this java code to do it:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package org.servDroid.settings;
  3.  
  4.  
  5.  
  6. import org.servDoid.web.R;
  7.  
  8.  
  9.  
  10. import android.app.Dialog;
  11.  
  12. import android.content.Context;
  13.  
  14. import android.os.Bundle;
  15.  
  16. import android.util.Log;
  17.  
  18. import android.view.View;
  19.  
  20. import android.widget.Button;
  21.  
  22. import android.widget.EditText;
  23.  
  24.  
  25.  
  26. public class MyDialog extends Dialog {
  27.  
  28.  
  29.  
  30.         private Button okButton;
  31.  
  32.  
  33.  
  34.         private Button cancelButton;
  35.  
  36.  
  37.  
  38.         private EditText nameEditText;
  39.  
  40.  
  41.  
  42.         private String value;
  43.  
  44.  
  45.  
  46.         public MyDialog(Context context) {
  47.  
  48.                 super(context);
  49.  
  50.                 // TODO Auto-generated constructor stub
  51.  
  52.         }
  53.  
  54.  
  55.  
  56.         public String getString() {
  57.  
  58.                 return value;
  59.  
  60.         }
  61.  
  62.  
  63.  
  64.         // @Override
  65.  
  66.         protected void onCreate(Bundle savedInstanceState) {
  67.  
  68.                 super.onCreate(savedInstanceState);
  69.  
  70.                 Log.d("ServDroid", "Dialog created");
  71.  
  72.                 setContentView(R.layout.dialog);
  73.  
  74.  
  75.  
  76.                 okButton = (Button) findViewById(R.id.okButton);
  77.  
  78.                 cancelButton = (Button) findViewById(R.id.cancelButton);
  79.  
  80.  
  81.  
  82.                 nameEditText = (EditText) findViewById(R.id.nameEditText);
  83.  
  84.  
  85.  
  86.                 okButton.setOnClickListener(new View.OnClickListener() {
  87.  
  88.                         public void onClick(View v) {
  89.  
  90.                                 value = nameEditText.getText().toString();
  91.  
  92.                                 dismiss();
  93.  
  94.                         }
  95.  
  96.                 });
  97.  
  98.                 cancelButton.setOnClickListener(new View.OnClickListener() {
  99.  
  100.                         public void onClick(View v) {
  101.  
  102.                                 cancel();
  103.  
  104.                         }
  105.  
  106.                 });
  107.  
  108.  
  109.  
  110.         }
  111.  
  112.  
  113.  
  114. }
  115.  
  116.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


But I don't know how to get the nameEditText input text and transfer it to the main Activity. Anybody can help me?

Thanks in advance and sorry for my English.
puxdroid
Developer
Developer
 
Posts: 49
Joined: Wed Nov 25, 2009 11:57 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests