[android-beginners] Re: The content of the adapter has changed but ListView did not receive a notification

2010-07-28 Thread nimusi
Thanks, Justin, that has solved the problem.

On 27 July, 22:00, Justin Anderson  wrote:
> Use startActivityForResult instead of startActivity.  Then when you get back
> to the listView you can add the item and update there.  There are some very
> specific things you need to do to get startActivityForResult to work
> properly and return the stuff you want to return to the main activity, so
> you may want to search StackOverflow and this group for
> startActivityForResult...
>
> Hope that helps,
> Justin
>
> --
> There are only 10 types of people in the world...
> Those who know binary and those who don't.
> --
>
>
>
> On Tue, Jul 27, 2010 at 2:35 PM, nimusi  wrote:
> > I have an app in which the main activity is a listview.  Clicking on
> > an item in the list item opens a new activity which is a detail view
> > of that item.  The detail view has navigate buttons which traverse
> > through the list displaying details for the currently selected item.
> > This is working as expected.
>
> > Users need to be able to add, edit and delete items.  In the main
> > activity I have an 'Add Item' menu item which allows the user to add
> > an item.  The detail view has an 'Add Item' button.
>
> > I thought I would be able to reuse the code for both cases by opening
> > a dialog in a helper class which accepts a new item and updates the
> > list view (and also the detail view if that was where it was called
> > from).  This is raising an Exception 'The content of the adapter has
> > changed but ListView did not receive a notification'.
>
> > Having googled this I am told that I cannot update the UI thread in a
> > sub-thread.  Does this mean that I have to replicate the add item code
> > in each activity? Or am I going about this in the wrong way and I
> > should be doing something else.
>
> > NiMuSi
> >http://www.nimusi.net/blog
>
> > --
> > 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- Hide quoted text -
>
> - Show quoted text -

-- 
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


[android-beginners] The content of the adapter has changed but ListView did not receive a notification

2010-07-27 Thread nimusi
I have an app in which the main activity is a listview.  Clicking on
an item in the list item opens a new activity which is a detail view
of that item.  The detail view has navigate buttons which traverse
through the list displaying details for the currently selected item.
This is working as expected.

Users need to be able to add, edit and delete items.  In the main
activity I have an 'Add Item' menu item which allows the user to add
an item.  The detail view has an 'Add Item' button.

I thought I would be able to reuse the code for both cases by opening
a dialog in a helper class which accepts a new item and updates the
list view (and also the detail view if that was where it was called
from).  This is raising an Exception 'The content of the adapter has
changed but ListView did not receive a notification'.

Having googled this I am told that I cannot update the UI thread in a
sub-thread.  Does this mean that I have to replicate the add item code
in each activity? Or am I going about this in the wrong way and I
should be doing something else.

NiMuSi
http://www.nimusi.net/blog

-- 
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


[android-beginners] Re: Returning values from dialog

2010-07-20 Thread nimusi
Thank you, that works.

On 20 July, 16:40, Kostya Vasilyev  wrote:
> 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"  написал:
>
> 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 
> athttp://stackoverflow.com/questions/tagged/android
>
> To unsubscribe from this group, send email to
> android-beginners+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://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


[android-beginners] Returning values from dialog

2010-07-20 Thread nimusi
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
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en