如何获取recyclerview项目的视图,该视图将在滚动显示时显示

时间:2019-11-14 07:07:43

标签: android android-studio android-recyclerview view

实际上,我在屏幕打开时在recylerview中有25个数据,在屏幕上可以看到13个数据,我想查看14个项目中的每个项目的视图,但是当我的位置变为14时,我就可以查看

视图视图= recyclerView.getChildAt(i);

我正在查看null 这是我的代码,当我单击ave按钮时,我想在其中查看每个项目

private class SaveDataTask extends AsyncTask<Void, Void, Boolean> {
       final UpdateActivity instance;
        String errorMessage;

     SaveDataTask(UpdateActivity instance) {
            this.instance = instance;
        }

        @Override
        protected void onPreExecute() {
            instance.showProgressDialog();
        }

        @Override
        protected Boolean doInBackground(Void... params) {
            String getXmlName = "";
            String getXmlString = "";
            statusSuccessHashMap.clear();
            updateActivityStatus.clear();

            try {
                Logger.d(instance, LOGGER_TAG, "Adding asset to structure");
                String tenant = InstallParam.getInstance().getInstallParam(AppConstant.PARAM_APPSERVER_TENANT);

                for (int i = 0; i < listViewData.size(); i++) {
                    View view = recyclerView.getChildAt(i);
                    isEditted = (CheckBox) view.findViewById(R.id.layout_editablerow);

                    if(!isEditted.isChecked()){
                        continue;
                    }

                    TextView posEditText = (TextView) view.findViewById(R.id.layout_overview_pos);
                    EditText descriptionEditText = (EditText) view.findViewById(R.id.layout_overview_desc);
                    EditText priceEditText = (EditText) view.findViewById(R.id.layout_overview_price);
                    EditText quantityEditText = (EditText) view.findViewById(R.id.layout_overview_qtyh);
                    EditText tradeEditText = (EditText) view.findViewById(R.id.layout_overview_trade);
                    CheckBox completeCheckBox = (CheckBox) view.findViewById(R.id.layout_overview_completed);
                    rowLayout   = (LinearLayout)view.findViewById(R.id.layout_woupdate_row);
                    errorSign = (TextView)findViewById(R.id.layout_overview_error);

                    if(completeCheckBox.isChecked()){
                        completedVal = "true";
                    }else {
                        completedVal = "false";
                    }
                    if(priceEditText.getText() != null){
                        priceVal = priceEditText.getText().toString().replaceAll("[\\-\\+\\.\\^:,]","");
                        int priceDecimal = getNumberOfDecimalPlace(priceEditText.getText().toString());
                        pricePosVal = String.valueOf(priceDecimal);
                    }

                    if(posEditText.getText() != null){
                        posVal = posEditText.getText().toString();
                    }
                    if(quantityEditText.getText() != null){
                        quantityVal = quantityEditText.getText().toString().replaceAll("[\\-\\+\\.\\^:,]","");;
                        int quantityDecimal = getNumberOfDecimalPlace(quantityEditText.getText().toString());
                        quantityPosVal = String.valueOf(quantityDecimal);
                    }

                    descriptionVal = descriptionEditText.getText().toString();
                    tradeVal = tradeEditText.getText().toString();

                    getXmlName = "xmltemplate/wawebservices/MPCUST87_SyncWOActivities_001.xml";
                    getXmlString = GenericUtility.readAssetAsString(instance, getXmlName);
                    getXmlString = getXmlString.replace("$WORKORDER$", AppSession.getSessionUser().getWorkOrderno());
                    getXmlString = getXmlString.replace("$ACTIVITY$", posVal);
                    getXmlString = getXmlString.replace("$NOTE$", descriptionVal);
                    getXmlString = getXmlString.replace("$PRICE$", priceVal);
                    getXmlString = getXmlString.replace("$PRICEPOS$", pricePosVal);
                    getXmlString = getXmlString.replace("$QUANTITYHOUR$", quantityVal);
                    getXmlString = getXmlString.replace("$QUANTITYHOURPOS$", quantityPosVal);
                    getXmlString = getXmlString.replace("$TRADE$", tradeVal);
                    getXmlString = getXmlString.replace("$COMPLETE$", completedVal);
                    getXmlString = GenericUtility.enrichCommonXMLParameters(getXmlString, AppSession.getSessionUser().getUserCode(), tenant);
                    try{
                        WebServiceUtil.callSOAPWebService(instance, getXmlString);
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                isEditted.setChecked(false);
                            }
                        });

                        setErrorForNotSavedAct(updateActivityStatus);
                    }catch (Exception ex){
                        statusSuccessHashMap.put("Failed",ex.getMessage());
                        updateActivityStatus.put(posVal,statusSuccessHashMap);
                        setErrorForNotSavedAct(updateActivityStatus);
                    }
                }

            } catch (Exception xe) {
                statusSuccessHashMap.put("Failed",xe.getMessage());
                updateActivityStatus.put(posVal,statusSuccessHashMap);
                Logger.e(instance, LOGGER_TAG, xe.getMessage(), xe);
                errorMessage = xe.getMessage();
                int strlength=errorMessage.length();
                if (strlength == 17)
                {
                    return true;
                }else{
                    return false;
                }
            } finally {
            }
            return true;
        }

        @Override
        protected void onPostExecute(final Boolean success) {
            instance.hideProgressDialog();
            if (success) {
                String msg= LabelCache.getInstance().getLabel("msupdateact.save.success", "Activity Updated Succesfully*");
                showToast(msg);
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(instance);
                builder.setTitle(LabelCache.getInstance().getLabel("global.alert.title.error", "Error*"));
                builder.setMessage(errorMessage);
                builder.setPositiveButton(LabelCache.getInstance().getLabel("global.alert.title.ok", "Ok*"), new DialogInterface
                        .OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
                AlertDialog alert = builder.create();
                alert.setCanceledOnTouchOutside(false);
                alert.show();
            }
        }

        @Override
        protected void onCancelled() {

        }
    }

这是代码

0 个答案:

没有答案