标签:
正确的方法
gvFlow.performItemClick(gvFlow.getChildAt(0),0,gvFlow.getAdapter().getItemId(0));
gvFlow.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //选择充值金额 mBean = rechargeListNum.get(position); // mBean.setPrice(0.01f); float saleMoney = mBean.getPrice() * mBean.getDiscount(); DecimalFormat dFormat = new DecimalFormat("##0.00"); realitePayMoney = dFormat.format(saleMoney); phone_charge_btn.setText(getString(R.string.btn_pay_now) + ":¥" + realitePayMoney); //更新界面按钮状态 setSelectedMoneyItem(view); LogUtil.logI("==========onItemClick===realitePayMoney:" + realitePayMoney+" view:"+view); } });
以上触发的点击事件,在 clickListener里面可以获取到正确的view ,并对view进行状态改变。
如果用
gvFlow.performItemClick(gvFlow.getAdapter().getView(mActivePosition,null,null),mActivePosition,gvFlow.getAdapter().getItemId(mActivePosition));
注:mActivePosition是你要点击的GridView或ListView的position
如果用上面的方法触发点击事件,在 clickListener里面不能得到正确的view ,对view的任何修改都 无效。
标签:
原文地址:http://www.cnblogs.com/longhs/p/5345849.html