Ankush
Ankush

Reputation: 6927

Creating a TextView once checkbox is clicked

In my activity I would like a TextView to appear below a checkbox once the checkbox has been clicked. How should I do this. Do I need to create a new activity that will display the new TextView below the checkbox. Or can I just use the same activity as before to accomplish this.

Thanks!

Upvotes: 0

Views: 1955

Answers (8)

pavel
pavel

Reputation: 1701

I think this can help you...

 holder.checkBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (holder.checkBox.isChecked()==true){

                holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            }
            else {

                holder.title.setPaintFlags(holder.title.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
            }
        }
    });

Upvotes: 0

user3419146
user3419146

Reputation: 1

You can try this

 holder.checkBox.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (holder.checkBox.isChecked()==true){

                holder.title.setPaintFlags(holder.title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
            }
            else {

                holder.title.setPaintFlags(holder.title.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
            }
        }
    });

Upvotes: 0

RockandRoll
RockandRoll

Reputation: 411

This should help you. try this..

checkBxAutomaticLogin
            .setOnCheckedChangeListener(new OnCheckedChangeListener() {
                public void onCheckedChanged(CompoundButton buttonView,
                        boolean isChecked) {
                    if (isChecked) {
                        ViewGroup automaticLoginLyt = (ViewGroup) findViewById(R.id.yourlayout);
                        LayoutInflater.from(SomeActivity.this).inflate(
                                R.layout.your_layout,
                                automaticLoginLyt, true);
                        editTxtUsername = (EditText) findViewById(R.id.edit_txt_user_name);
                        editTxtPassword = (EditText) findViewById(R.id.edit_txt_password);
                    } else {
                        ViewGroup automaticLoginLyt = (ViewGroup) findViewById(R.id.your_layout);
                        View v = automaticLoginLyt
                                .findViewById(R.id.your_layout);
                        if (v != null) {
                            automaticLoginLyt
                                    .removeView(v);
                        }
                    }
                }
            });

Upvotes: 0

Syn3sthete
Syn3sthete

Reputation: 4171

you can do it in same activity

in the xml create the TextView below CheckBox and yourTextView.visibility=gone

in your class write the following code :

 yourCheckBox.setonClickListener=new onClickListener(){

            @Override
            public void onClick(View v) {
            if(checkBox.isChecked())
              yourTextView.setVisibility(View.VISIBLE);
            else
              yourTextView.setVisibility(View.GONE);

}

}

Upvotes: 2

Lokesh
Lokesh

Reputation: 5378

Try this:

    TextView tv;
 CheckBox cbS;
 OnClickListener checkBoxListener;
 checkBoxListener =new OnClickListener() {

 @Override
 public void onClick(View v) {
 tv=(TextView)findViewById(R.id.tvDetails);
 //by default keep textview visibility as invisible in xml file;
tv.setVisibility(View.GONE)
 };

 cbS.setOnClickListener(checkBoxListener);

Upvotes: 1

David Wasser
David Wasser

Reputation: 95626

Add the TextView to your layout and set android:visibility="gone".

In your onCheckboxClicked() set the visibility of the TextView to VISIBLE

Upvotes: 3

Nirav Ranpara
Nirav Ranpara

Reputation: 13785

You have to create textbox in onChecked event .

you can refer this :

http://www.mysamplecode.com/2011/10/android-programmatically-generate.html

Upvotes: 1

Shruti
Shruti

Reputation: 5591

no need to create new activity .Just add textview in your layout file and keep it invisible..when you check the checkbox just make that Textview visible.

Upvotes: 2

Related Questions