当指标从响应中出现错误时,如何隐藏整个视图?

时间:2018-05-02 07:59:05

标签: android android-fragments adapter android-adapter

我收到的回复是filterMatchIndicator == true或false来自回复。

如果是的话,我需要显示所有视图。如果它是假的,我需要隐藏视图。

但问题是,视图显示空间。当关闭时,我隐藏适配器中的视图。 [但空间即将到来]。当打开时,我显示一切。

public class RetailerListLastAdapter extends RecyclerView.Adapter<RetailerListLastAdapter.FilterViewHolder> {

    public Context context;
    private List<Retailer> data;
    private static final String TAG = RetailerListLastAdapter.class.getSimpleName();
    private boolean isChecked;
    private SharedPreferences mSharedPreferences;


    public RetailerListLastAdapter(List<Retailer> data, Context context) {
        this.data = data;
        this.context = context;
    }
    public RetailerListLastAdapter(List<Retailer> data, Context context,boolean isChecked) {
        this.data = data;
        this.context = context;
        this.isChecked= isChecked;
    }

    @Override
    public RetailerListLastAdapter.FilterViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.route_plan_se_list_row, parent, false);
        return new RetailerListLastAdapter.FilterViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(RetailerListLastAdapter.FilterViewHolder holder, int position) {
        Retailer retailerList = data.get(position);
        Boolean filterMatchIndicator = retailerList.getFilterMatchIndicator();
        mSharedPreferences = context.getSharedPreferences(AppConstants.MyPREFERENCES, MODE_PRIVATE);
       // Boolean userFilterPassIndicator = retailerList.getUserFilterPassInd();
      //  Log.e("userFilterPassIndicator","userFilterPassIndicator"+userFilterPassIndicator);


if(AppUtils.getToggle(mSharedPreferences).equalsIgnoreCase("1") || filterMatchIndicator==true){
    Log.e("going here one","going here one");
    Log.e("one togglebutton","togglebutton"+AppUtils.getToggle(mSharedPreferences));

    holder.mark.setVisibility(View.VISIBLE);
    holder.layout_holders.setVisibility(View.VISIBLE);
}
else if(AppUtils.getToggle(mSharedPreferences).equalsIgnoreCase("0") || filterMatchIndicator==false)
{
    Log.e("going here zero","going here zero");
    Log.e("zero togglebutton","togglebutton"+AppUtils.getToggle(mSharedPreferences));

    holder.mark.setVisibility(View.INVISIBLE);
    holder.layout_holders.setVisibility(View.GONE);
}
        /*if (!filterMatchIndicator) {
            holder.mark.setVisibility(View.INVISIBLE);
        }
        else{
            holder.mark.setVisibility(View.VISIBLE);
        }*/
    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    public class FilterViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public TextView name, number;
        public CircleImageView avatar;
        public ImageView sellIn, sellOut, growth,mark;
        public LinearLayout lyout_color_mark;
        public LinearLayout layout_holders; //entire layout holder

        public FilterViewHolder(View v) {
            super(v);
            avatar = v.findViewById(R.id.recycle_profile);
            name = v.findViewById(R.id.recycle_txt_acc_name);
            number = v.findViewById(R.id.recycle_txt_acc_num);

            sellIn = v.findViewById(R.id.recycle_sellIn);
            sellOut = v.findViewById(R.id.recycle_sellout);
            growth = v.findViewById(R.id.recyle_growth);
            mark = v.findViewById(R.id.recycle_color_mark);
            lyout_color_mark = v.findViewById(R.id.lyout_color_mark);
            layout_holders = v.findViewById(R.id.layout_holders);

            avatar.setOnClickListener(this);
            name.setOnClickListener(this);
            number.setOnClickListener(this);
            sellIn.setOnClickListener(this);
            sellOut.setOnClickListener(this);
            growth.setOnClickListener(this);
            mark.setOnClickListener(this);
            lyout_color_mark.setOnClickListener(this);

        }

在MainFragment中:

private void BindDataToView(List<Retailer> list,String filteredRetailersCount) {
        if (list.size() == 0) {
            Toast.makeText(mContext, R.string.no_retailer_found, Toast.LENGTH_SHORT).show();
            view.findViewById(R.id.no_retailer_found).setVisibility(View.VISIBLE);
            view.findViewById(R.id.reatiler_found).setVisibility(View.GONE);
        } else {
            view.findViewById(R.id.no_retailer_found).setVisibility(View.GONE);
            view.findViewById(R.id.reatiler_found).setVisibility(View.VISIBLE);
            TextView count = view.findViewById(R.id.dafatar_filter_txtvw);
            count.setText(String.valueOf(list.size()));
        }
        mListData.clear();
        mListData.addAll(list);
        mMenuRetailerFilterAdapter.notifyDataSetChanged();

    }

toggleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
             isChecked = ((ToggleButton) view).isChecked();

            if (isChecked) {
                AppUtils.saveToggle(mSharedPreferences,"1");
                APIInitialize();
            } else {
                APIInitialize();
                AppUtils.saveToggle(mSharedPreferences,"0");
                // Disable vibrate
            }
        }
    });

enter image description here

1 个答案:

答案 0 :(得分:0)

我希望这能解决您的问题

import time
from concurrent.futures import ThreadPoolExecutor

while True:
    qty_fetched = 6
    time.sleep(random_secs(0.5))
    pending_updates = fetch_pending_updates(qty_fetched) #list of dicts

    if pending_updates:
        prio = 2 #some variable number between 0 and 4

        if prio > 3:
            qty_threads = 1

        elif prio == 0 or prio == 1:
            qty_threads = 4

        else:
            qty_threads = 3

        #the following lines changed
        with ThreadPoolExecutor(max_workers=qty_threads) as e:
            for pu in pending_updates:
                e.submit(self.run_update_NEW, pu)

    else:
        time.sleep(2)