activity 接回返回值

activity 接回返回值

今天做订单列表显示 点击某一项显示订单详细信息,在详细activity中用户可以选择取消订单(未支付的状态下)当用户取消订单后订单列表也要改变状态,原来最初做法是所加载绑定显示放在了

onStart方法中这样只要加载页面就重新绑定不这样可以解决上面问题,但问题是这样每次都要重新加载大家都知道 GPRS流量那叫一个宝贵啊。所以改变当前做法利用activity的onActivityResult方法

父activity方法如下

startActivityForResult(intent, 0);跳转activity时候用这个

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {    
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode==Activity.RESULT_OK)
        {
            String stateString = (String) data.getExtras().get("status");
            if(null!=stateString)
            {
                adapter.modifyOrderItem(position_x, "status", "dead");
            }
        }
    }

 子actiivty方法

btnBack.setOnClickListener(new OnClickListener() {         
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if(bolstatus)
                {
                    Intent intent = new Intent();
                    Bundle bundle = new Bundle();
                    bundle.putString("status", "dead");
                    intent.putExtras(bundle);
                    setResult(Activity.RESULT_OK, intent);
                }
                my_order_info.this.finish();
            }
        });

  

bolstatus判断用户是否点击取消按钮
adapter方法
public void modifyOrderItem(int position,String key,String value)
    {
        listMaps.get(position).remove(key);
        listMaps.get(position).put(key,value);
        this.notifyDataSetChanged();
    }

  成功解决这样做避免每次加载节省流量

posted on 2015-05-13 13:49  rojas  阅读(178)  评论(0编辑  收藏  举报