Skip to content

Instantly share code, notes, and snippets.

@Airfixed
Last active April 1, 2016 06:25
Show Gist options
  • Save Airfixed/d930ef55a8231bb9291db9f6635de683 to your computer and use it in GitHub Desktop.
Save Airfixed/d930ef55a8231bb9291db9f6635de683 to your computer and use it in GitHub Desktop.
For William Smith
import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
int fuel = 3400;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
EditText fuelLoadField = (EditText) findViewById(R.id.Fuel_load_field);
fuelLoadField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
EditText fuelEditText = (EditText) findViewById(R.id.Fuel_load_field);
String fuelString = fuelEditText.getText().toString();
// Error check to avoid a null error
if ("".equals(fuelString)){
fuel = 0;
fuelEditText.setText(String.valueOf(fuel));
fuelEditText.setSelection(0); //Trying to figure out the best place for cursor
// need to add calc here
return;
}
// Set the fuel value and then perform the W&B Calc.
fuel = Integer.parseInt(fuelString.toString());
// Error check to avoid over fuel
if (fuel > 14518) {
fuel = 14518;
fuelEditText.setText(String.valueOf(fuel));
fuelEditText.setSelection(5);
}
// need to add calc here
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment