Reputation: 6927
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
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
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
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
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
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
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
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
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