它显示在A活动中,并在B活动中更改了数据。
活动:
protected List<CommentEntity> mDataList;
protected ListView mListView;
protected BaseListAdapter mAdapter;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
int position = data.getIntExtra("position", -1);
if (position > -1) {
CommentEntity entity = (CommentEntity) data.getSerializableExtra(AppVars.Keys.EXTRA_ENTITY);
mDataList.set(position, entity); // I want this list update
mAdapter.notifyDataSetChanged();
} else {
// error
}
}
public class BaseListAdapter extends BaseAdapter {
@Override
public int getCount() {
return mDataList == null ? 0 : mDataList.size();
}
@Override
public Object getItem(int position) {
return mDataList == null ? null : mDataList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// actually this adapter is written in MyBaseFragment, and the child
// Fragment will override setupItemView() method.it's working fine
return setupItemView(position, convertView, parent);
}
}
B活动:
private CommentEntity mCommentEntity;
// the list below is inside CommentEntity, QuoteEntity is extends HashMap<>.
private List<QuoteEntity> mQuoteList;
private QuoteAdapter mAdapter;
public void update(QuoteEntity newQuote) {
mQuoteList.add(newQuote);
mCommentEntity.setReplyRows(mQuoteList);
mAdapter.notifyDataSetChanged();// This adapter is just working fine.
setResult(-1, getIntent().putExtra(AppVars.Keys.EXTRA_ENTITY, mCommentEntity));
}
答案 0 :(得分:0)
尝试重置listview,而不是使用notifyDataSetChanged();
ListView lv = (ListView)FindViewById(R.id.lv);
BaseListAdapter aa = new BaseListAdapter(//constructor's parameters);
lv.setAdapter(aa);