Listview没有根据条件正确显示按钮

时间:2015-08-14 12:17:47

标签: android android-fragments android-listview

enter image description here

enter image description here

这是两个屏幕。条件是当订单状态为取消时,不需要显示编辑按钮,否则应显示编辑按钮。不一致的是,在某些取消项目中,它在某些展示时没有显示。片段是一样的。您可以比较两个屏幕。这是我的代码:

package com.logisticaforce.logisticaforce.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.IconTextView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.logisticaforce.logisticaforce.ApplicationController;
import com.logisticaforce.logisticaforce.ApplicationInfo;
import com.logisticaforce.logisticaforce.R;
import com.logisticaforce.logisticaforce.activity.NavDrawerActivity;
import com.logisticaforce.logisticaforce.dialog.ValidationDialog;
import com.logisticaforce.logisticaforce.fragment.OrderFragment;
import com.logisticaforce.logisticaforce.object.OrdersObject;
import com.logisticaforce.logisticaforce.util.AndroidUtils;
import com.logisticaforce.logisticaforce.util.Constants;
import com.logisticaforce.logisticaforce.util.SharedPrefrenceUtils;
import com.logisticaforce.logisticaforce.webservice.WebServiceResponseListener;
import com.logisticaforce.logisticaforce.webservice.factory.WebServiceRequestExecutorFactory;
import com.logisticaforce.logisticaforce.webservice.json.RequestClass;
import com.logisticaforce.logisticaforce.webservice.json.request.DataObject;
import com.logisticaforce.logisticaforce.webservice.json.request.Request;
import com.logisticaforce.logisticaforce.webservice.json.request.RequestCommand;
import com.logisticaforce.logisticaforce.webservice.json.response.Response;

import java.util.ArrayList;
import java.util.List;

public class OrderAdapter extends ArrayAdapter<OrdersObject> implements WebServiceResponseListener {
    private Context mContext;
    private ArrayList<OrdersObject> mList;
    LinearLayout linearLayout,layout;
    private OrdersObject myitem = null;
    private OrderFragment orderFragObject;
    TextView textView;
    private List<Integer> view = new ArrayList<>();
    public OrderAdapter(Context mContext, ArrayList<OrdersObject> mList,OrderFragment orderFragObject){
        super(mContext, R.layout.activity_orders, mList);
        this.mContext = mContext;
        this.mList = mList;
        this.orderFragObject=orderFragObject;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public OrdersObject getItem(int position) {
        return mList.get(position);
    }

    private static class ViewHolder{
        private LinearLayout orderMain,orderTitleMain;
        private TextView orderName;
        private TextView orderRate;
        private TextView orderTitle;
        private TextView orderId;
        private TextView orderBy;
        private TextView orderStatus;
        private TextView orderCreateDate;
        private TextView orderDeliveryDate;
        private LinearLayout collapseImage;
        private LinearLayout getLayout;
        private IconTextView btnOrderEdit;

    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        OrdersObject item = getItem(position);
        ViewHolder mViewHolder;
        if(convertView==null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.activity_orders,parent,false);
            mViewHolder = new ViewHolder();
            mViewHolder.orderName = (TextView)convertView.findViewById(R.id.order_name_lbl);
            mViewHolder.orderRate = (TextView)convertView.findViewById(R.id.order_rate);

            mViewHolder.orderTitle = (TextView)convertView.findViewById(R.id.order_title);
            mViewHolder.orderId = (TextView)convertView.findViewById(R.id.orderIdLbl);
            mViewHolder.orderBy = (TextView)convertView.findViewById(R.id.order_by_lbl);
            mViewHolder.orderStatus = (TextView)convertView.findViewById(R.id.order_status_lbl);
            mViewHolder.orderCreateDate = (TextView)convertView.findViewById(R.id.order_crdate);
            mViewHolder.orderDeliveryDate = (TextView)convertView.findViewById(R.id.order_deldate);
            mViewHolder.orderMain = (LinearLayout)convertView.findViewById(R.id.orderMain);
            mViewHolder.orderTitleMain=(LinearLayout)convertView.findViewById(R.id.orderTitleMain);
            mViewHolder.getLayout=(LinearLayout)convertView.findViewById(R.id.drpDownViewContainer);
            mViewHolder.btnOrderEdit=(IconTextView)convertView.findViewById(R.id.btnOrderEdit);
            textView=(TextView)convertView.findViewById(R.id.titleLbl);

            mViewHolder.btnOrderEdit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    myitem = (OrdersObject)view.getTag();
                    if(null!= SharedPrefrenceUtils.getString(mContext,"openOrderId")){
                        ValidationDialog.showDialog(orderFragObject.getChildFragmentManager(),R.string.fAlreadyOpen);
                    }else{
                        sendEditOrderRequest(myitem);
                    }
                }
            });

            mViewHolder.collapseImage = (LinearLayout)convertView.findViewById(R.id.orderMain);
            mViewHolder.collapseImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Integer id =(Integer) v.getTag();
                    if(view.contains(id)){
                        view.remove(id);
                    }else{
                        view.add(id);
                    }
                    notifyDataSetChanged();
                }
            });

            convertView.setTag(mViewHolder);
        }else{
            mViewHolder = (ViewHolder)convertView.getTag();
        }
        //Expanding and Collapsing
        mViewHolder.collapseImage.setTag(position);
        if(view.contains(position)){
            mViewHolder.getLayout.setVisibility(View.VISIBLE);
        }else{
            mViewHolder.getLayout.setVisibility(View.GONE);
        }

        mViewHolder.btnOrderEdit.setTag(item);
        mViewHolder.orderName.setText(item.getOrderName());
        mViewHolder.orderRate.setText("$"+String.valueOf(item.getOrderPrice()));

        mViewHolder.orderTitle.setText(item.getOrderTitle());
        mViewHolder.orderId.setText(String.valueOf(item.getOrderId()));
        mViewHolder.orderBy.setText(item.getOrderBy());
        mViewHolder.orderStatus.setText(item.getOrderStatus());
        mViewHolder.orderCreateDate.setText((item.getOrderCreateDate()));
        mViewHolder.orderDeliveryDate.setText(String.valueOf(item.getOrderDeliveryDate()));

        //Setting Theme


        mViewHolder.orderRate.setTextColor(Color.parseColor(ApplicationInfo.getSdfColor(mContext)));



        if(item.getOrderStatus().equals("Canceled")){
            mViewHolder.orderMain.setBackgroundColor(mContext.getResources().getColor(R.color.canceled));
            mViewHolder.orderName.setTextColor(mContext.getResources().getColor(R.color.white));
            mViewHolder.orderTitleMain.setBackgroundColor(mContext.getResources().getColor(R.color.canceled1));
        }else{
            mViewHolder.orderMain.setBackgroundColor(Color.parseColor(ApplicationInfo.getPdColor(mContext)));
            mViewHolder.orderName.setTextColor(Color.parseColor(ApplicationInfo.getPlfColor(mContext)));
            mViewHolder.orderTitleMain.setBackgroundColor(Color.parseColor(ApplicationInfo.getPlColor(mContext)));

            if(ApplicationController.allowPlacedOrderEditing.equals("Y"))
            {
                mViewHolder.btnOrderEdit.setVisibility(View.VISIBLE);
            }else{
                mViewHolder.btnOrderEdit.setVisibility(View.GONE);
            }
        }

       return convertView;
    }

    public void sendEditOrderRequest(OrdersObject item){
        Request rq = new Request();
        RequestCommand rc=new RequestCommand();
        rc.setId("R1");
        rc.setParserVersion("1");
        RequestClass rt1=new RequestClass();
        rt1.setBatchSize(Constants.BATCH_SIZE);
        rt1.setName("manageOrder");
        rt1.setStartRow("0");
        List<DataObject> attr=new ArrayList<>();
        DataObject do1=new DataObject();
        do1.setName("action");
        do1.setValue("reopenOrder");
        attr.add(do1);
        DataObject do2=new DataObject();
        do2.setName("openOrderId");
        if(null!=SharedPrefrenceUtils.getString(mContext,"openOrderId")){
            do2.setValue(SharedPrefrenceUtils.getString(mContext,"openOrderId"));
        }else{
            do2.setValue("");
        }
        attr.add(do2);
        DataObject do3=new DataObject();
        do3.setName("customerOrderId");
        do3.setValue(String.valueOf(item.getOrderId()));
        attr.add(do3);
        DataObject do4=new DataObject();
        do4.setName("serviceLocationId");
        do4.setValue(SharedPrefrenceUtils.getString(mContext, "serviceLocationId"));
        attr.add(do4);
        rt1.setParams(attr);
        rt1.setResultAttributes(null);
        rt1.setRequestParam(rc);
        rq.setRequest(rc);
        Gson gs=new Gson();
        String jsonString=new Gson().toJson(rq);
        Log.i("TAG2", "Request String Edit Order : " + jsonString);

        WebServiceRequestExecutorFactory.getWebServiceExecutor(mContext, rq, this).execute();
    }

    @Override
    public void onWebServiceResponse(Response resp, String tag) {
        if(null!=resp){
            List result=resp.getResponse().getCmd();
            if(AndroidUtils.getResultParams(result, "name")!=null) {
                if(AndroidUtils.getResultParams(result,"name").equals("manageOrder")){
                    if (AndroidUtils.getResultParams(result, "result").equals("OK")) {
                        SharedPrefrenceUtils.putString(mContext,"openOrderId",String.valueOf(myitem.getOrderId()));
                        ((NavDrawerActivity)orderFragObject.getActivity()).displayView(4);
                    }else if (AndroidUtils.getResultParams(result, "result").equals("ERROR")) {
                        ValidationDialog.showDialog(orderFragObject.getChildFragmentManager(), R.string.fCommonError);
                    }
            }
        }else{
                ValidationDialog.showDialog(orderFragObject.getChildFragmentManager(), R.string.fCommonError);
          }
        }
    }
}

0 个答案:

没有答案