Android 8(Oreo)BaseAdapter的getView()未第二次调用

时间:2018-09-07 05:53:15

标签: android baseadapter android-8.0-oreo

我正在重新设计用于移动应用程序的平板电脑应用程序时,遇到一个问题,即不仅在 Android 8(Oreo)上调用我的基本适配器的func timeString(time: TimeInterval) -> String { let hours = Int(time) / 3600 let minutes = Int(time) / 60 % 60 let seconds = Int(time) % 60 return String(format:"%02i:%02i:%02i", hours, minutes, seconds) } 方法在较低的设备上正常工作。

这是我的适配器的文件

它调用GetView(),然后再不返回任何内容

getCount()

这是我的原木猫

public class JSAEquipmentAdapter extends BaseAdapter {

    Context context;

    ArrayList<JSAEquipmentData> arrayJsaEquipmentData;
    MyHelper myHelper;

    public JSAEquipmentAdapter(Context context, ArrayList<JSAEquipmentData> arrayJSaEquipmentData){
        this.context = context;
        this.arrayJsaEquipmentData = arrayJSaEquipmentData;
        myHelper= MyHelper.getInstance(context);
    }

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

    @Override
    public Object getItem(int position) {
        return arrayJsaEquipmentData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.row_jsa_equipment,null);

        final ViewHolder viewHolder = new ViewHolder();

        viewHolder.txtEquipmentName = (TextView) convertView.findViewById(R.id.txt_equipment_name);
        viewHolder.radioGroup = (RadioGroup) convertView.findViewById(R.id.radioGroup1);
        viewHolder.ivComment = (ImageView) convertView.findViewById(R.id.imgComment);
        viewHolder.edComment = (EditText) convertView.findViewById(R.id.edComment);
        viewHolder.edComment.setTag(position);
        viewHolder.edComment.addTextChangedListener(new CustomTextWatcher(viewHolder.edComment, AppConstants.JSA_EQUIPMENT_FRAGMENT));
        viewHolder.llReviews = (LinearLayout) convertView.findViewById(R.id.llReviews);

        viewHolder.txtEquipmentName.setText(arrayJsaEquipmentData.get(position).getEquipmentName());
        viewHolder.ivComment.setVisibility(View.VISIBLE);
        if (arrayJsaEquipmentData.get(position).getSelectedOption() != -1)
        {
            RadioButton radioBtn = (RadioButton) viewHolder.radioGroup.getChildAt(arrayJsaEquipmentData.get(position).getSelectedOption());
            radioBtn.setChecked(true);
        }
        if (arrayJsaEquipmentData.get(position).isCommentViewVisible()){
            viewHolder.edComment.setVisibility(View.VISIBLE);
            viewHolder.edComment.setText(arrayJsaEquipmentData.get(position).getComment());
        }

        viewHolder.radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                int radioButtonID = viewHolder.radioGroup.getCheckedRadioButtonId();
                View radioButton = viewHolder.radioGroup.findViewById(radioButtonID);
                int selectedIndex = viewHolder.radioGroup.indexOfChild(radioButton);

                arrayJsaEquipmentData.get(position).setSelectedOption(selectedIndex);

                if (selectedIndex == 1 || selectedIndex == 2)
                {
                    arrayJsaEquipmentData.get(position).setCommentViewVisible(true);
                    viewHolder.edComment.setVisibility(View.VISIBLE);
                    viewHolder.edComment.setText(arrayJsaEquipmentData.get(position).getComment());
                }
                else{
                    arrayJsaEquipmentData.get(position).setCommentViewVisible(false);
                    viewHolder.edComment.setVisibility(View.GONE);
                    myHelper.hideKeyBoard(viewHolder.edComment, AppConstants.KEYBOARD_TEXT);

                }


            }
        });

        viewHolder.ivComment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (viewHolder.edComment.getVisibility() == View.GONE) {
                    arrayJsaEquipmentData.get(position).setCommentViewVisible(true);
                    viewHolder.edComment.setVisibility(View.VISIBLE);
                    viewHolder.edComment.setText(arrayJsaEquipmentData.get(position).getComment());
                } else {
                    arrayJsaEquipmentData.get(position).setCommentViewVisible(false);
                    viewHolder.edComment.setVisibility(View.GONE);
                }
            }
        });

        viewHolder.edComment.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!hasFocus) {
                    arrayJsaEquipmentData.get(position).setComment(viewHolder.edComment.getText().toString());
                }
            }
        });

        return convertView;
    }

    class ViewHolder {
        TextView txtEquipmentName;
        RadioGroup radioGroup;
        ImageView ivComment;
        EditText edComment;
        LinearLayout llReviews;
    }
}

0 个答案:

没有答案