The counter doesnt seem to increase when ever the edittext changes
- by Mabulhuda
Im using Edit-texts and i need when ever an edit-text is changed to increment a counter by one but the counter isnt working , I mean the app starts and everything but the counter doesnt seem to change please help here is the code
public class Numersys extends Activity implements TextWatcher {
EditText mark1 ,mark2, mark3,mark4,mark5,mark6 , hr1 ,hr2,hr3,hr4,hr5,hr6;
EditText passed, currentavg;
TextView tvnewavg ;
Button calculate;
double marks , curAVG , NewAVG ;
String newCumAVG;
int counter , hrs , curHr , NewHr;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.numersys);
mark1=(EditText)findViewById(R.id.mark1n);
mark2=(EditText)findViewById(R.id.mark2n);
mark3=(EditText)findViewById(R.id.mark3n);
mark4=(EditText)findViewById(R.id.mark4n);
mark5=(EditText)findViewById(R.id.mark5n);
mark6=(EditText)findViewById(R.id.mark6n);
hr1=(EditText)findViewById(R.id.ethour1);
hr2=(EditText)findViewById(R.id.ethour2);
hr3=(EditText)findViewById(R.id.ethour3);
hr4=(EditText)findViewById(R.id.ethour4);
hr5=(EditText)findViewById(R.id.ethour5);
hr6=(EditText)findViewById(R.id.ethour6);
passed=(EditText)findViewById(R.id.etPassCn);
currentavg=(EditText)findViewById(R.id.etCavgn);
tvnewavg=(TextView)findViewById(R.id.tvcAVGn);
mark1.addTextChangedListener(this);
mark2.addTextChangedListener(this);
mark3.addTextChangedListener(this);
mark4.addTextChangedListener(this);
mark5.addTextChangedListener(this);
mark6.addTextChangedListener(this);
calculate=(Button)findViewById(R.id.bAvgCalcn);
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId())
{
case 0:
break;
case 1:
hrs=Integer.valueOf(hr1.getText().toString());
marks=Double.valueOf(mark1.getText().toString())*Integer.valueOf(hr1.getText().toString());
curHr=Integer.valueOf(passed.getText().toString());
curAVG=Double.valueOf(currentavg.getText().toString())*curHr;
NewHr= curHr+hrs;
NewAVG= (marks+curAVG)/NewHr;
break;
case 2:
hrs=Integer.valueOf(hr1.getText().toString())+Integer.valueOf(hr2.getText().toString());
marks=Double.valueOf(mark1.getText().toString())*Integer.valueOf(hr1.getText().toString())
+Double.valueOf(mark2.getText().toString())*Integer.valueOf(hr2.getText().toString());
curHr=Integer.valueOf(passed.getText().toString());
curAVG=Double.valueOf(currentavg.getText().toString())*curHr;
NewHr= curHr+hrs;
NewAVG= (marks+curAVG)/NewHr;
break;
case 3:
hrs=Integer.valueOf(hr1.getText().toString())+Integer.valueOf(hr2.getText().toString())
+Integer.valueOf(hr3.getText().toString());
marks=Double.valueOf(mark1.getText().toString())*Integer.valueOf(hr1.getText().toString())
+Double.valueOf(mark2.getText().toString())*Integer.valueOf(hr2.getText().toString())
+Double.valueOf(mark3.getText().toString())*Integer.valueOf(hr3.getText().toString());
curHr=Integer.valueOf(passed.getText().toString());
curAVG=Double.valueOf(currentavg.getText().toString())*curHr;
NewHr= curHr+hrs;
NewAVG= (marks+curAVG)/NewHr;
break;
case R.id.bAvgCalcn:
newCumAVG=String.valueOf(NewAVG);
tvnewavg.setText(newCumAVG);
}
}
});
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
if(mark1.hasFocus())
{
counter = counter+1;
}
if(mark2.hasFocus())
{
counter = counter+1;
}
if(mark3.hasFocus())
{
counter = counter+1;
}
if(mark4.hasFocus())
{
counter = counter+1;
}
if(mark5.hasFocus())
{
counter = counter+1;
}
if(mark6.hasFocus())
{
counter = counter+1;
}
}