我正在使用ArrayAdapter和ListView。我有一个活动 A 和活动 B 。活动 A 启动活动 B (startActivityForResult()
),当活动 B 完成后,它会将结果返回给活动 A 即可。
活动 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
}
}
我不明白我做错了什么!我尝试了很多解决方案,但仍然没有得到它。
答案 0 :(得分:-1)
尝试移动
pAdapter = new PrayerAdapter(this, R.layout.prayer_list_item,
prayerList);
在onCreate中的if语句之前