如何从android中的列表视图中隐藏textView来自listView项目

时间:2015-03-19 06:21:11

标签: android listview

我有一个列表视图。其中我有状态的textview。现在我想在取消状态时禁用该文本视图。在这个列表项中我有一个textview(骑行状态)现在当骑行状态被取消时我设置适配器我想要隐藏取消骑行文本视图从列表项目。我试过但这不适合我。谢谢你的到来。

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final DrawerListItemHolder holder;
        if (convertView == null) {
            holder = new DrawerListItemHolder();

        holder.mRideStatus = (TextView) convertView
                    .findViewById(R.id.ride_status);
            holder.mCancelRide = (TextView) convertView
                    .findViewById(R.id.cancle_ride);
            holder.mViewRide = (TextView) convertView
                    .findViewById(R.id.view_ride);

            convertView.setTag(holder);
        } else {
            holder = (DrawerListItemHolder) convertView.getTag();
        }



        String rideType = BravoDataController.getInstance(mContext)
                .getTripStatusDescription(
                        mMyRides.get(position).getTripStatusCode());
        holder.mRideStatus.setText(rideType);

        holder.mRideStatus.setTextColor(Color.parseColor(BravoDataController
                .getInstance(mContext).getTripStatusColor(
                        mMyRides.get(position).getTripStatusCode())));

        if (rideType.equals(ConstantsUtils.CANCELLED)) {
            holder.mCancelRide.setVisibility(View.GONE);
        }


        return convertView;
    }

1 个答案:

答案 0 :(得分:0)

将getView中的条件更改为

if (rideType.equals(ConstantsUtils.CANCELLED)) {
            holder.mCancelRide.setVisibility(View.GONE);
        }else{
        holder.mCancelRide.setVisibility(View.VISIBLE);
}

并在标志更改时调用此adapter.notifyDataSetChanged()