I have a method in my class named InvokeService() and inside It I am storing an Int value from a remoteservice.
like this
int hvactemp=remoteService.getHvacTemp();
and I am storing this value in to a textview.
drivertmpcount.setText(Integer.toString(hvactemp));
Now I want to incresae and decrease this value on button click.
I have two buttons declared in my code and the problem is
If I click right button the value is Increasing
suppose the value is 30 its increasing like 30,31,32,33,34,35 and so on..
But the problem is when I click left button its not decresing from the value Which I have present, as I said after incresing the value is 35 so now If I press left button it should go like this 34,32,31,32
but its decreasing from 30,29,28,27 instead of 35,34,32,31
How to solve this?
Here is my code.
private void invokeService() {
if (conn == null) {
// Toast.makeText(CarHome.this, "Cannot invoke - service not bound",
// Toast.LENGTH_SHORT).show();
} else {
try {
System.out.println(remoteService);
int rpm = remoteService.getEnginRPM();
int temp = remoteService.getTemperature();
// int battery = remoteService.getBatteryLevel();
int speed = remoteService.getSpeed();
final int hvactemp = remoteService.getHvacTemp();
System.out.println("Raghav hvac" + hvactemp);
System.out.println("jaydeep speed" + speed);
// rpm_text.setText(rpm);
drivertmpcount.setText(Integer.toString(hvactemp));
driverbtnright.setOnClickListener(new View.OnClickListener() {
int hvactemp=remoteService.getHvacTemp();
public void onClick(View v) {
// TODO Auto-generated method stub
hvactemp++;
drivertmpcount.setText(Integer.toString(hvactemp));
System.out.println("Raghav hvac" + hvactemp);
}
});
driverbtnleft.setOnClickListener(new View.OnClickListener() {
int hvactemp=remoteService.getHvacTemp();
public void onClick(View v) {
// TODO Auto-generated method stub
// drivertmpcount.setText(Integer.toString(hvactemp));
hvactemp --;
drivertmpcount.setText(Integer.toString(hvactemp));
System.out.println("Raghav decrement hvac" + hvactemp);
}
});
You are wrong with code flow.
Remove this
int hvactemp=remoteService.getHvacTemp();from two click Listener and declarehvactempas a class variable.