Damir
Damir

Reputation: 56249

How to put text above or below with checkbox?

How to put text above or below with checkbox ? Is that possible with checkBox in android ?

Upvotes: 5

Views: 3409

Answers (2)

ArteFact
ArteFact

Reputation: 537

Here is what I did for my project :

    LinearLayout llsomething = new LinearLayout(this);
    Checkbox cbSomething = new CheckBox(this);

    TextView tvSomething = new TextView(this);
    tvSomething.setText(R.string.something);

    llsomething.addView(cbSomething);
    llsomething.addView(tvSomething);

EDIT :

You can also make your layout clickable to do more "natural" :

llSomething.setClickable(true);
llSomething.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
              LinearLayout layout = (LinearLayout) v;
              CheckBox check = (CheckBox) layout.getChildAt(0);
              if(check.isChecked())
                  check.setChecked(false);
              else
                  check.setChecked(true);
        }
}

Upvotes: 0

Mohammad Ersan
Mohammad Ersan

Reputation: 12444

try to use Layout, even LinearLayout add your Checkbox to the Layout and add TextView up or down to the Checkbox

Upvotes: 2

Related Questions