jeudi 19 juillet 2018

Create dynamic edittext besides dynamic checkbox

I want to create dynamic edit text besides dynamic checkbox. But I can't set position of edittext. I created dynamic checkbox like this:

for (int i = 0; i < parentCategoryList.size(); i++) {
            checkbox = new CheckBox(getContext());
            checkbox.setText(parentCategoryList.get(i).getName());
            checkbox.setChecked(false);
            checkbox.setId(parentCategoryList.get(i).getId());
            checkbox.setTag(i);
            checkbox.setOnCheckedChangeListener(checkboxListener);

            linearLayout.addView(checkbox);

    }

Now on check I call createEditText function

checkboxListener = new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            int id = buttonView.getId();
            if (isChecked) {
                createEditText((Integer) buttonView.getTag());
            } 
        }
    };

My createEditText function:

final EditText editText=new EditText(getContext());
    editText.setId(position);
    editText.setClickable(false);
    editText.setCompoundDrawablesWithIntrinsicBounds(0,0,0,0);




Aucun commentaire:

Enregistrer un commentaire