Reset TextBox with checkbox

Quickly share your Android Code Snippets here...

Reset TextBox with checkbox

Postby JonnySnip3r » Fri Apr 17, 2009 12:50 pm

Hey guys im kinda new to android i was wondering if anyone can help me, below is a snippet of code which displays a message one checked and also once unchecked. i have 2 textbox in my project named


@+id/username
@+id/password

here is my checkbox snippet

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);
  2.  
  3.         checkbox.setOnClickListener(new OnClickListener() {
  4.  
  5.             public void onClick(View v) {
  6.  
  7.          
  8.  
  9.                 if (checkbox.isChecked()) {
  10.  
  11.                     Toast.makeText(loginsystempro.this, "I will remember you!", Toast.LENGTH_SHORT).show();
  12.  
  13.                 } else {
  14.  
  15.                     Toast.makeText(loginsystempro.this, "Forgotten!", Toast.LENGTH_SHORT).show();
  16.  
  17.                 }
  18.  
  19.             }
  20.  
  21.         });
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


how do i make it clear the text boxes once unchecked?

thanks guys
JonnySnip3r
Developer
Developer
 
Posts: 30
Joined: Wed Apr 08, 2009 1:23 pm

Top

Postby SlumberMachine » Fri May 15, 2009 6:59 pm

I would do this:

dialog is the my textbox in my project. The names can be found in your main.xml file where you defined them.
Code: Select all
  TextView textView;
  textView = (TextView) findViewById(R.id.dialogue);
  textView.setText("");


Obviously you need to manage that into your if/then statement properly to clear out the box. Not sure if this is what you are looking for or not. Hope it helps.
SlumberMachine
Developer
Developer
 
Posts: 39
Joined: Tue Feb 24, 2009 9:00 pm

Postby JonnySnip3r » Sat May 16, 2009 3:17 pm

Thanks dude this is perfect for me :)
JonnySnip3r
Developer
Developer
 
Posts: 30
Joined: Wed Apr 08, 2009 1:23 pm

Re: Reset TextBox with checkbox

Postby chinna872 » Sun Jul 24, 2011 4:12 am

uname = (TextView) findViewById(R.id.username);
passwd=(TextView)findViewById(R.id.password);
final CheckBox checkbox = (CheckBox) findViewById(R.id.checkbox);

checkbox.setOnClickListener(new OnClickListener() {

public void onClick(View v) {



if (checkbox.isChecked()) {

Toast.makeText(loginsystempro.this, "I will remember you!", Toast.LENGTH_SHORT).show();

} else {
uname.setText(" ");
passwd.setText(" ");
Toast.makeText(loginsystempro.this, "Forgotten!", Toast.LENGTH_SHORT).show();

}

}

});
chinna872
Freshman
Freshman
 
Posts: 5
Joined: Sat Jul 23, 2011 7:11 am

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 4 guests