彈出的dialog如何更新下面的listview

兩種情況

1.兩個activity之間跳轉,當back的時候,主activity顯示會調用onResume()方法,所以刷新可以這樣處理:

 @Override
 protected void onResume() {
  super.onResume();
  //onPause==>onResume,重新獲取lv數據,刷新頁面
  freeAdapter.setMData(AppDataManage.getData(true));
  freeAdapter.notifyDataSetChanged();// 通知listview頁面重繪

  paymentAdapter.setMData(AppDataManage.getData(false));
  paymentAdapter.notifyDataSetChanged();
  recentpayment.setMData(AppDataManage.getRecentData());
  recentpayment.notifyDataSetChanged();
 }

2.如果activiy里彈出dialog,并不會調用onResume()方法,處理方式如下:

 /**
  * @param context
  * @param title
  * @param item
  * @param refreshAdapter listview's adapter做數據更新
  */
 public static void showProgreeCommentDialog(Context context, String title,
   final App item,final AppCommentAdapter refreshAdapter) {
  LayoutInflater inflater = LayoutInflater.from(context);
  final View textEntryView = inflater.inflate(
    com.cms.activity.R.layout.dialogcomment, null);
  AlertDialog.Builder builder = new AlertDialog.Builder(context);
  builder.setTitle(title);
  builder.setIcon(com.cms.activity.R.drawable.comment);
  builder.setView(textEntryView);
  builder.setPositiveButton(SingleApplication.nfcstore.getResources().getString(R.string.finish), new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int which) {
    int num = item.getComments().size();
    AppComment comment = new AppComment();
    comment.setCommentDate(new Date());
    Long zero = new Long(0);
    comment.setId(++num+zero);
    EditText etcomment = (EditText) textEntryView.findViewById(R.id.dialog_comment);
    comment.setContent(etcomment.getText().toString());
    EditText etuser = (EditText) textEntryView.findViewById(R.id.dialog_username);
    comment.setCritics(etuser.getText().toString());
    RatingBar rb = (RatingBar) textEntryView.findViewById(R.id.dialog_ratingBar);
    float rating=rb.getRating();
    comment.setGrade(rating);
    item.addComment(comment);
    dialog.dismiss();
    if(null != refreshAdapter){
     refreshAdapter.setMData(AppDataManage.getCommentData(item));//設置新的數據
     refreshAdapter.notifyDataSetChanged();
     
    }
   }
  });
  builder.setNegativeButton(SingleApplication.nfcstore.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int which) {
    dialog.dismiss();
   }
  });
  builder.create().show();
 }

 

attention:一定要重置更新后的數據,再通知更新.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值