Try removing 'final' from 'final mytitle'.

'final' in Java means you are telling the compiler you are going to assign
the value once, a kind of self-check. Consequent assingments are flagged as
an error.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

20.07.2010 18:26 пользователь "nimusi" <nimus...@gmail.com> написал:

I am a newbie trying to learn Java at the same time as learning
Android.

I need to show a dialog containing two EditTexts and return the
values:

I am using the following code:

public static String addItem(final Context context) {
               final String myTitle = "";

               final Dialog myDialog = new Dialog(context);
               Window window = myDialog.getWindow();
               window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
               myDialog.setTitle("Add Item");
               myDialog.setContentView(R.layout.additem);
               final EditText txtTitle =
(EditText)myDialog.findViewById(R.id.txtTitle);
               final EditText txtNote =
(EditText)myDialog.findViewById(R.id.txtNote);
               Button btnOK =
(Button)myDialog.findViewById(R.id.btnAddItem);
               Button btnCancel =
(Button)myDialog.findViewById(R.id.btnCancelAddItem);
               btnOK.setOnClickListener(new View.OnClickListener() {
                       @Override
                       public void onClick(View v) {
                               String thisTitle =
txtTitle.getText().toString();
                               String thisNote =
txtNote.getText().toString();
                               if (thisTitle.length() == 0) {
                                       Toast.makeText(context, "Title is
blank!",
Toast.LENGTH_LONG).show();
                                       return;
                               }
                               if (thisNote.length() == 0) {
                                       Toast.makeText(context, "Note cannot
be blank",
Toast.LENGTH_LONG).show();
                                       return;
                               }
                               myDialog.dismiss();
                               myTitle = thisTitle + "---" + thisNote;
 <---- error here
                       }
               });
               btnCancel.setOnClickListener(new View.OnClickListener() {
                       @Override
                       public void onClick(View v) {
                               myDialog.dismiss();
                       }
               });
               myDialog.show();
               return myTitle;
       }

Within the Click handler for the button I get the error 'the final
local variable myTitle cannot be assigned, since it is defined in an
emclosing type.  I would be grateful for any help with this.


Nimusi

--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com<android-beginners%2bunsubscr...@googlegroups.com>
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to