How to get values from Dialog when clicked OK?

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

How to get values from Dialog when clicked OK?

Postby prajkti.khadse » Fri Apr 03, 2009 10:09 am

Hi, i want to retrive the text through the EditText of AlertDialog

i've tried textEntryView.getText()
but it asks me to typecast the textEntryView to EditText
when i do so, i get a java.lang.ClassCastException :roll:

here's the code m working with


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. protected Dialog onCreateDialog(int id)
  2.  
  3.     {
  4.  
  5.         LayoutInflater infalter = LayoutInflater.from(this);
  6.  
  7.                 final View textEntryView = infalter.inflate(R.layout.alert_dialog_text_entry, null);
  8.  
  9.                 AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
  10.  
  11.                
  12.  
  13.    
  14.  
  15.                 dialogBuilder.setTitle("Edit Free Text");
  16.  
  17.        
  18.  
  19.    
  20.  
  21.         dialogBuilder.setView(textEntryView);
  22.  
  23.        
  24.  
  25.                 dialogBuilder.setPositiveButton("Save", new OnClickListener(){
  26.  
  27.  
  28.  
  29.                         @Override
  30.  
  31.                         public void onClick(DialogInterface dialog, int which)
  32.  
  33.                         {
  34.  
  35.                                 CharSequence text = ((EditText) textEntryView).getText();
  36.  
  37.                                 mFreeTxtView.setText(text);
  38.  
  39.                                
  40.  
  41.                         }
  42.  
  43.                        
  44.  
  45.                 });
  46.  
  47.                 dialogBuilder.setNegativeButton("Cancel", null);
  48.  
  49.                
  50.  
  51.                 return dialogBuilder.create();
  52.  
  53.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

}


and here's the alert_dialog_text_entry.xml file


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.    <?xml version="1.0" encoding="utf-8"?>
  2.  
  3.  
  4.  
  5. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  6.  
  7.    android:layout_width="fill_parent"
  8.  
  9.    android:layout_height="wrap_content"
  10.  
  11.    android:orientation="vertical">
  12.  
  13.  
  14.  
  15.     <EditText
  16.  
  17.        android:id="@+id/ALERT_DIALOG_EDIT_TEXT"
  18.  
  19.        android:layout_height="100px"
  20.  
  21.        android:layout_width="fill_parent"
  22.  
  23.        android:layout_marginLeft="20dip"
  24.  
  25.        android:layout_marginRight="20dip"
  26.  
  27.        android:maxHeight="100px"
  28.  
  29.        android:gravity="top|left"
  30.  
  31.    />
  32.  
  33.    
  34.  
  35. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4


can anybody please tell me how to get the text from the EditText when user clicks on Save...????

please help me out...
prajkti.khadse
Developer
Developer
 
Posts: 32
Joined: Thu Mar 19, 2009 1:01 pm
Location: Bangalore

Top

Postby prajkti.khadse » Fri Apr 03, 2009 1:47 pm

Ok, i'll answer myself.. :)

i achieved it by creating a new Activity with Theme as Theme.Dialog

and got the values as we generally get it through Intent. :)
prajkti.khadse
Developer
Developer
 
Posts: 32
Joined: Thu Mar 19, 2009 1:01 pm
Location: Bangalore

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 3 guests