I am trying to disable EditText if Switch is off I have made If-else for it.
But my CompoundButton buttonView cannot be resolved. What can be the issue?
Here's my code:
public class MainActivity extends AppCompatActivity {
public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
EditText editText = (EditText) findViewById(R.id.editText);
/** Called when the user taps the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent newxml = new Intent(this, DisplayMessageActivity.class);
String message = editText.getText().toString();
newxml.putExtra(EXTRA_MESSAGE, message);
startActivity(newxml);
TextView displayText = (TextView) findViewById(R.id.displayText);
displayText.setText(message);
String someText = "Your Message";
TextView yourMessage = (TextView) findViewById(R.id.yourMessage);
yourMessage.setText(someText);
}
final Switch switch1 = (Switch) findViewById(R.id.switch1);
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// true if the switch is in the On position
if(isChecked){
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);
}else{
editText.setFocusableInTouchMode(false);
editText.setFocusable(false);
}
}
});
}
Error image
Code Image
I have rewritten the portion of code below. You may try it at your end.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Switch switch1 = (Switch) findViewById(R.id.switch1);
switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// true if the switch is in the On position
if(isChecked){
editText.setFocusableInTouchMode(true);
editText.setFocusable(true);
}else{
editText.setFocusableInTouchMode(false);
editText.setFocusable(false);
}
}
});
}
..... then other code.
Related
This question already has answers here:
How do I pass data between Activities in Android application?
(53 answers)
Closed 6 years ago.
public class StartActivity extends AppCompatActivity {
private boolean addition=true;
private boolean subtraction=false;
private boolean multiplication=false;
private boolean division=false;
public static final String ADDITION = "";
public static final String SUBTRACTION = "";
public static final String MULTIPLICATION= "";
public static final String DIVISION = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
final Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
CheckBox additionCheckBox = (CheckBox)findViewById(R.id.additionCheckBox);
CheckBox multiplicationCheckBox = (CheckBox)findViewById(R.id.multiplicationCheckBox);
CheckBox divisionCheckBox = (CheckBox)findViewById(R.id.divisionCheckBox);
CheckBox subtractionCheckBox = (CheckBox)findViewById(R.id.subtractionCheckBox);
Button playButton = (Button)findViewById(R.id.playButton);
additionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked()){
addition = true;
}else{
addition = false;
}
}
});
multiplicationCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked()){
multiplication = true;
}else{
multiplication= false;
}
}
});
subtractionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked()){
subtraction = true;
}else{
subtraction = false;
}
}
});
divisionCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(buttonView.isChecked()){
division = true;
}else{
division = false;
}
}
});
playButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(!addition && !subtraction && !multiplication && !division){
final Dialog dialog = new Dialog(StartActivity.this);
dialog.setContentView(R.layout.custom_dialog);
dialog.setTitle("My custom dialog");
//set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.textView);
text.setText("Android custom dialog example!");
Button button = (Button) dialog.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
} else{
Intent i = new Intent(StartActivity.this, Main2Activity.class);
i.putExtra(ADDITION,addition);
i.putExtra(SUBTRACTION,subtraction);
i.putExtra(MULTIPLICATION,multiplication);
i.putExtra(DIVISION,division);
startActivity(i);
}
}
});
}
This is the starting activity and I am trying to sent to the next activity the 4 boolean variables one for each basic math operation to see which one the user has checked. but they are always false in the next activity and i dont know why. here is the next activity:
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
final Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
Intent i = getIntent();
Bundle b = i.getExtras();
boolean addition = b.getBoolean("ADDITION");
boolean subtraction = Boolean.getBoolean("SUBTRACTION");
boolean multiplication = b.getBoolean("MULTIPLICATION");
boolean division = b.getBoolean("DIVISION");
int operatorCounter =0;
TextView additionTextView = (TextView) findViewById(R.id.additionTextView);
TextView subtractionTextView = (TextView) findViewById(R.id.subtractionTextView);
TextView multiplicationTextView = (TextView) findViewById(R.id.multiplicationTextView);
TextView divisionTextView = (TextView) findViewById(R.id.divisionTextView);
if (addition) {
additionTextView.setText("addition:checked");
}else{
additionTextView.setText("addition:not checked");
}
if (subtraction) {
subtractionTextView.setText("subtraction:checked");
}else{
subtractionTextView.setText("subtraction:not checked");
}
if (multiplication) {
multiplicationTextView.setText("multiplication:checked");
}else{
multiplicationTextView.setText("multiplication:not checked");
}
if (division) {
divisionTextView.setText("division:checked");
}else{
divisionTextView.setText("division:not checked");
}
}
}
I am setting the text in the textbox to see if the value is passed correctly but is always false. Sorry for bad code I'm quite new in android, actually is the forth mini project in android and its school homework.
The problem I see are the id's:
public static final String ADDITION = "";
public static final String SUBTRACTION = "";
public static final String MULTIPLICATION= "";
public static final String DIVISION = "";
this should be something and different like:
public static final String ADDITION = "ADDITION";
public static final String SUBTRACTION = "SUBTRACTION";
public static final String MULTIPLICATION= "MULTIPLICATION";
public static final String DIVISION = "DIVISION";
and use the same values for retrieving the values in the other activity
Try this code for both sending and getting values.
Pass to first Activity:
Intent i = new Intent(getBaseContext(), NameOfActivity.class);
i.putExtra("my_boolean_key", myBooleanVariable);
startActivity(i);
Retrieve in Second Activity:
Bundle bundle = getIntent().getExtras();
boolean myBooleanVariable = bundle.getBoolean("my_boolean_key");
Its because you are not setting value in globle variable, so you need to set first globle variable value like this
public static final String ADDITION = "ADDITION";
public static final String SUBTRACTION = "SUBTRACTION";
public static final String MULTIPLICATION= "MULTIPLICATION";
public static final String DIVISION = "DIVISION";
then set it
Intent i = new Intent(StartActivity.this, Main2Activity.class);
i.putExtra(ADDITION,addition);
i.putExtra(SUBTRACTION,subtraction);
i.putExtra(MULTIPLICATION,multiplication);
i.putExtra(DIVISION,division);
startActivity(i);
than aceess value from another activity like this
boolean addition = getIntent().getExtras().getBoolean("ADDITION");
boolean sub = getIntent().getExtras().getBoolean("SUBTRACTION");
boolean mult = getIntent().getExtras().getBoolean("MULTIPLICATION");
boolean division = getIntent().getExtras().getBoolean("DIVISION");
Make sure you are using same key to Put and to Get data.
Also update
boolean subtraction = Boolean.getBoolean("SUBTRACTION");
To
boolean subtraction = b.getBoolean("SUBTRACTION");
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("BoolName", true);
startActivity(intent );
Retrieve boolean value from intent :
Boolean yourBool = getIntent().getExtras().getBoolean("BoolName");
I will use this post to show why a mcve is useful since this is a perfect example, I will use his code, cleaning the useless part and we will quickly find the problem, I don't deserve or ask for upvote but don't downvote either, if you are against this answer, comment and I will remove it if need.
So, let clean the code, I am only interested in the Intent creation here. So let clean the rest and keep the variables/constants used. To be minimal, we only need one boolean, let's keep the first putBoolean.
public class StartActivity extends AppCompatActivity {
private boolean addition=true;
public static final String ADDITION = "";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
Button playButton = (Button)findViewById(R.id.playButton);
playButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(StartActivity.this, Main2Activity.class);
i.putExtra(ADDITION,addition);
startActivity(i);
}
});
Well, this is better. Fits on one screen and we see the problem directly.
Same thing with the recovering:
public class Main2Activity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Intent i = getIntent();
Bundle b = i.getExtras();
boolean addition = b.getBoolean("ADDITION");
}
}
Mmmh, could use StartActivity.ADDITION here ...
I hope code will help you
Intent intent = new Intent(this, NextActivity.class);
intent.putExtra("yourBoolName", true);
protected void onCreate(Bundle savedInstanceState) {
Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName");
}
Intent intt=new Intent(this,YourAcivity.class);
intt.putExtra("BooleanKey",true);
startActivity(intt);
protected void onCreate(Bundle savedInstanceState) {
Boolean yourBool = getIntent().getExtras().getBoolean("yourBoolName");
}
I have integrated Parse signup & login in my app.
I signed up successfully but when I'm logging back again after logging out, I'm getting this ParseException: com.parse.ParseRequest$ParseRequestException: invalid login parameters.
Here's LoginWithEmail.java file's code:
public class LoginWithEmail extends AppCompatActivity {
EditText mUsername;
EditText mPassword;
public String name, email, userID;
Intent profileIntent;
ParseUser user;
String login_username;
String login_password;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_with_email);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mUsername = (EditText) findViewById(R.id.userNameEmail);
login_username = mUsername.getText().toString();
mPassword = (EditText) findViewById(R.id.userPasswordEmail);
login_password = mPassword.getText().toString();
findViewById(R.id.email_login_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
loginWithEmail();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
private void loginWithEmail() {
ParseUser.logInInBackground(login_username, login_password, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
// Hooray! The user is logged in.
Log.d(login_username, login_username+"success");
profileIntent = new Intent(LoginWithEmail.this, ProfileActivity.class);
startActivity(profileIntent);
} else {
// Signup failed. Look at the ParseException to see what happened.
Log.d("error signingup email", e.toString());
Log.d(login_username, login_username+"error", e);
Log.d(login_password, login_password+"error", e);
AlertDialog.Builder builder = new AlertDialog.Builder(LoginWithEmail.this);
builder.setTitle("");
builder.setMessage(e.getMessage());
builder.setPositiveButton(android.R.string.ok, null);
}
}
});
}
}
Here's ProfileActivity.java file's code (where I am logging out):
public class ProfileActivity extends AppCompatActivity {
CircleImageView mProfileImage;
Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Bundle bundle = getIntent().getExtras();
mProfileImage = (CircleImageView) findViewById(R.id.user_profile_image);
TextView mUsername = (TextView) findViewById(R.id.userName);
TextView mEmailID = (TextView) findViewById(R.id.aboutUser);
byte[] byteArray = getIntent().getByteArrayExtra("user_pic");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
mProfileImage.setImageBitmap(bmp);
mUsername.setText(bundle.getString("userName"));
mEmailID.setText(bundle.getString("userEmail"));
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_profile, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_logout) {
ParseUser.logOut();
navigateToLogin();
}
return super.onOptionsItemSelected(item);
}
private void navigateToLogin() {
Intent intent = new Intent(this, SignUpScreen.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
}
Please let me know what is going wrong here!
Your problem is these lines inside your onCreate() method:
login_username = mUsername.getText().toString();
login_password = mPassword.getText().toString();
Just move those lines into this:
findViewById(R.id.email_login_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
loginWithEmail();
}
});
Like this:
findViewById(R.id.email_login_btn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
login_username = mUsername.getText().toString();
login_password = mPassword.getText().toString();
loginWithEmail();
}
});
I have editText in Setup Activity. I used SharedPreference for saving this value and get later. I passed this edittext value to another activity button text. Initially i need to hide the button. If edittext values are coming from sharedPreference i need to display the button.Thanks alot
public class Setup extends Activity implements AdapterView.OnItemSelectedListener {
EditText editText;
Button button;
Spinner spinner;
TextView text;
ArrayList<String> ar = new ArrayList<String>();
// String a=editText.getText().toString();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup);
button = (Button) findViewById(R.id.button1);
editText = (EditText) findViewById(R.id.ed1);
spinner = (Spinner) findViewById(R.id.spinner1);
text = (TextView) findViewById(R.id.back);
getnameButton();
ArrayAdapter<String> arr = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ar);
arr.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
spinner.setAdapter(arr);
spinner.setOnItemSelectedListener(this);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences preferences = getSharedPreferences("sample", 0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Name",editText.getText().toString());
editor.putInt("position",spinner.getSelectedItemPosition());
editor.commit();
Intent myIntent = new Intent(Setup.this, MainActivity.class);
startActivity(myIntent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_setup, menu);
return true;
}
public void getnameButton() {
Intent intent = getIntent();
String text1 = intent.getStringExtra("text1");
String text2 = intent.getStringExtra("text2");
String text3 = intent.getStringExtra("text3");
String text4 = intent.getStringExtra("text4");
String text5 = intent.getStringExtra("text5");
String text6 = intent.getStringExtra("text6");
String text7 = intent.getStringExtra("text7");
String text8 = intent.getStringExtra("text8");
ar.add(text1);
ar.add(text2);
ar.add(text3);
ar.add(text4);
ar.add(text5);
ar.add(text6);
ar.add(text7);
ar.add(text8);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
editText.setText(ar.get(position));
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
=>Activity Class
public class MainActivity extends Activity {
Button button1,button2,button3,button4,button5,button6,button7,button8;
TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1=(Button) findViewById(R.id.btn1);
button2=(Button) findViewById(R.id.btn2);
button3=(Button) findViewById(R.id.btn3);
button4=(Button) findViewById(R.id.btn4);
button5=(Button) findViewById(R.id.btn5);
button6=(Button) findViewById(R.id.btn6);
button7=(Button) findViewById(R.id.btn7);
button8=(Button) findViewById(R.id.btn8);
textView=(TextView) findViewById(R.id.txtsua);
getName();
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),Setup.class);
intent.putExtra("text1", button1.getText().toString());
intent.putExtra("text2",button2.getText().toString());
intent.putExtra("text3",button3.getText().toString());
intent.putExtra("text4", button4.getText().toString());
intent.putExtra("text5",button5.getText().toString());
intent.putExtra("text6",button6.getText().toString());
intent.putExtra("text7", button7.getText().toString());
intent.putExtra("text8", button8.getText().toString());
startActivity(intent);
}
});
// getnameButton();
}
public void getName() {
button1.setVisibility(View.GONE);
SharedPreferences preferences = getSharedPreferences("sample", 0);
String Namestr = (preferences.getString("Name", ""));
int position = (preferences.getInt("position", Integer.parseInt("")));
for (int i = 0; i < 8; i++) {
Button[] a = {button1, button2, button3, button4, button5, button6, button7, button8};
if (Namestr.length() > 0&&position==i) {
a[i].setVisibility(View.VISIBLE);
a[i].setText(preferences.getString("Name", ""));
}
break;
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}}
I am trying to add a basic setting to my app. I would like to change the hint of an EditText in one of my activities if the checkBox is unchecked.
preferences.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:key="PREF_SHOW_UNITS"
android:id="#+id/Check1"
android:title="Show units in Kinematics"
android:defaultValue="true" >
</CheckBoxPreference>
</PreferenceScreen>
SettingsActivity.java:
package com.supermath.jacobgb24.supermath;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import static com.supermath.jacobgb24.supermath.R.xml.preferences;
public class SettingsActivity extends PreferenceActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(preferences);
}
}
Code that I am trying to add changes to:
public class Kinematics extends ActionBarActivity {
static EditText tval, aval, vval, xval;
static double a, t, x, v;
static DecimalFormat fmt = new DecimalFormat("###,###.###");
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.klayout);
CheckBox cb1 = (CheckBox) findViewById(R.id.Check1);
tval = (EditText) findViewById(R.id.time);
aval = (EditText) findViewById(R.id.accel);
vval = (EditText) findViewById(R.id.velocity);
xval = (EditText) findViewById(R.id.xpos);
cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton checkbox, boolean isChecked) {
if (isChecked) {
tval.setHint("YAY");
} else {
tval.setHint("UNYAY");
}
}
});
}
Solved
Since I was using preferences I needed the following code:
PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean disp = prefs.getBoolean("PREF_SHOW_UNITS", true);
if(disp)
tval.setHint("t(s)");
tval.setHint("t(s)");
else if(!disp)
tval.setHint("UNYAY");
you can change the hint of the edittext on checkbox check via following:
your_checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton checkbox,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked)
{
your_edittext.setHint(textonChecked);
}
else
{
your_edittext.setHint(textonUnchecked);
}
}
});
//Get EditText
EditText editText1 = (EditText) findViewById(R.id.editText1);
//Get Checkbox
CheckBox cb1 = (Checkbox) findViewById(R.id.checkBox1);
//Add Listener to Checkbox
cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
//Set a hint to EditText
editText1.setHint("This is a hint!");
}
}
});
I have a problem here. I want to disable a edittext by using a checkbox. If checkbox is checked, edittext isa available, if not, it is disabled. But I'm having problems. Here is my code: Can anyone check on this. Accdng to eclipse, no error. But when I run it on my phone, the enabling/disabling is not functioning.
public class Order extends Activity {
private Button button1;
private EditText txtbox1,txtbox2;
private TextView tv;
CheckBox check1;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
txtbox1= (EditText) findViewById(R.id.editText1);
button1 = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.editText5);
txtbox2= (EditText) findViewById(R.id.editText2);
check1 = (CheckBox)findViewById(R.id.checkcheck);
button1.setOnClickListener(new clicker());
}
public void addListenerOncheck1() {
check1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
txtbox1.setFocusable(true);
txtbox1.setFocusableInTouchMode(true);
} else {
txtbox1.setFocusable(false);
txtbox1.setFocusableInTouchMode(false);
}
}
});
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String a,b;
Integer vis;
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
vis = Integer.parseInt(a)*2+Integer.parseInt(b)*3;
tv.setText(vis.toString());
}
}
}
you are nowhere adding your Listener by calling ur method addListenerOncheck1();
so put addListenerOncheck1(); add the end of you OnCreate method.
But I highly recommend you not to use all these additional self-made Classes for just adding listeners. Use the following code instead and add it into your OnCreate Method:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.order);
txtbox1= (EditText) findViewById(R.id.editText1);
button1 = (Button) findViewById(R.id.button1);
tv = (TextView) findViewById(R.id.editText5);
txtbox2= (EditText) findViewById(R.id.editText2);
check1 = (CheckBox)findViewById(R.id.checkcheck);
button1.setOnClickListener(new clicker());
check1.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked) {
txtbox1.setEnabled(false);
} else {
txtbox1.setEnabled(true);
}
}
});
button1.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
String a,b;
Integer vis;
a = txtbox1.getText().toString();
b = txtbox2.getText().toString();
vis = Integer.parseInt(a)*2+Integer.parseInt(b)*3;
tv.setText(vis.toString());
}
});
// This will make sure the user can only type numbers into the EditTexts:
txtbox1.setInputType(InputType.TYPE_CLASS_NUMBER);
txtbox2.setInputType(InputType.TYPE_CLASS_NUMBER);
// Code to disable editTexts at start once:
txtbox1.setEnabled(false);
txtbox2.setEnabled(false);
}