Changing value in Listview after editing in a new instance of clicked item?

I'm making my first android app and I'm new to this sort of development.

I have a list view which launches a new intent to an activity which populates it's information via the item you clicked on.

E.g.

List:

  • Person A
  • Person B
  • Person C

If I click on Person B, it'll take me to an intent with a textview populated to contain the text 'Person B'. Now what I want is to be able to change the value in that screen (to say, John) and update the list view (so it'd be:)

List:

  • Person A
  • John
  • Person C

But I can't figure it out, any ideas??

EDIT:

Current click listener which goes to new activity:

@Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Current item
            String person = ((TextView) view).getText().toString();

            // Launch new activity based on item
            Intent intent =  new Intent(getApplicationContext(), SinglePerson.class);
            intent.putExtra("person", person);
            startActivity(intent);

        }

Answers


you need to store your new value John back into the data array, so your list will contain the updated data. once that is done you can call the adapter's notifyDataChanged() method which will update the ListView


How are you passing "Person B" in your intent. Your going to have to provide the index of that object in your data array, in addition to the actual content. I would highly advise NOT sending the entire contents of your array since that can grow very quickly. Then once you get back to your original activity you can make the changes and redraw you list.

However, I would also suggest not making a totally new activity in the first place. You can achieve the same effect buy using fragments, or popup dialogs to perform your edits without having to switch back and forth between activities in the first place. That way your able to make all your edits on the fly and update the information in the same context.


Need Your Help

Using Html5 Notification in Blackberry Webworks

javascript html5 blackberry-10 blackberry-webworks

I am using HTML5 Local Notifications in Blackberry 10 (Higher Version BB z10) using webworks 1.0