如何以表格形式从数据库动态将复选框添加到列表视图中?

时间:2019-01-02 08:02:32

标签: java database android-studio checkbox android-listview

我正在创建复选框列表,数据来自数据库。复选框是动态呈现的。但是问题是,列表要么是水平方向出现的,要么是垂直方向出现的。我想以表格形式列出列表。
enter image description here enter image description here

 stateManager.Instance.getDefectListFromServer(new ICallback() {
        @Override
        public void run() {
            defectArrayList = stateManager.Instance.defectList;

            for (Defect defect:defectArrayList) {
                final CheckBox frontButton = new CheckBox(instance);
                frontButton.setText(defect.name);
                frontButton.setTag(defect);
                frontButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        instance.onCheckboxClicked(v);
                    }
                });
                switch (defect.type)
                {
                    case Front:
                        frontList.addView(frontButton);
                        break;
                    case Lining:
                        liningList.addView(frontButton);
                        break;
                    case Sleeve:
                        sleeveList.addView(frontButton);
                        break;
                    case Assembly:
                        assemblyList.addView(frontButton);
                        break;
                }
            }

0 个答案:

没有答案