-1

I am working on ArrayAdapter and ListView. I have an Activity A and Activity B. Activity A starts an Activity B (startActivityForResult()) and when Activity B is finished, it returns the result back to Activity A.

Activity A:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);
    listViewPrayerList = (ListView) findViewById(R.id.listView_prayerlist);
    prayerList = new ArrayList<PrayerSetting>();
    if (getIntent().hasExtra(Utils.PRAYER_LIST)) {
        prayerList.clear();
        prayerList.addAll((ArrayList<PrayerSetting>) getIntent()
                .getSerializableExtra(Utils.PRAYER_LIST));
        pAdapter = new PrayerAdapter(this, R.layout.prayer_list_item,
                prayerList);
  }
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (data != null && data.hasExtra(Utils.SETTINGS)) {
        PrayerSetting p = (PrayerSetting) data
                .getSerializableExtra(Utils.SETTINGS);
        prayerList.set(itemClickedPosition, p);
        pAdapter.notifyDataSetChanged(); // UI/List doesn't change
    }
}

I don't understand what I am doing wrong! I have tried many solutions but still don't get it.

  1. Stackoverflow Question 1
  2. Stackoverflow Question 2
  3. Stackoverflow Question 3
  4. Blogspot link
  5. Stackoverflow Question 4

I do understand that its a basic question. Thanks in Advance.

Community
  • 1
  • 1
Faizan Mubasher
  • 4,427
  • 11
  • 45
  • 81

1 Answers1

-1

Try moving

pAdapter = new PrayerAdapter(this, R.layout.prayer_list_item,
    prayerList);

before if statement in onCreate

Zoran
  • 1,484
  • 1
  • 10
  • 13