Here is my code. On line 111 (machineOD_input.setOnClickListener) you can see where I am trying to clear the string when the user clicks on it to change the data, but once it's cleared, the "NEXT" option in the keyboard doesn't work anymore, it gets stuck at first input.
At the moment I'm just working on clearing 1st input, once it's working I will do the same for all input.
What am I doing wrong, please?
package com.example.beno;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.view.View;
import android.view.Window;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.text.InputType;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
private EditText machineOD_input, pipeOD_input, pipe_length_input, drive_length_input, muck_up_input, jacking_speed_input;
private TextView lub_result, litre_per_meter_result, volume_per_pipe_result, volume_for_drive_result;
public static final String SHARED_PREFS = "sharedPrefs";
public static final String TBMODINPUT = "machineOD_input";
public static final String PIPEODINPUT = "pipeOD_input";
public static final String PIPELENGTHINPUT = "pipe_length_input";
public static final String DRIVELENGTHINPUT = "drive_length_input";
public static final String MUCKUPINPUT = "muck_up_input";
public static final String JACKINGSPEEDINPUT = "jacking_speed_input";
private String tbmODinputText, pipeODinputText, pipeLengthinputText, driveLengthinputText, muckupinputText, jackingSpeedinputText;
@SuppressLint("DefaultLocale")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Objects.requireNonNull(getSupportActionBar()).setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.toolbar_title_layout);
setContentView(R.layout.activity_main);
machineOD_input = findViewById(R.id.machineOD_input);
pipeOD_input = findViewById(R.id.pipeOD_input);
pipe_length_input = findViewById(R.id.pipe_length_input);
drive_length_input = findViewById(R.id.drive_length_input);
muck_up_input = findViewById(R.id.muck_up_input);
jacking_speed_input = findViewById(R.id.jacking_speed_input);
lub_result = findViewById(R.id.lub_result);
litre_per_meter_result = findViewById(R.id.litre_per_meter_result);
volume_per_pipe_result = findViewById(R.id.volume_per_pipe_result);
volume_for_drive_result = findViewById(R.id.volume_for_drive_result);
Button calculate = findViewById(R.id.calculate);
calculate.setOnClickListener(v -> {
if (machineOD_input.getText().toString().length() == 0) {
machineOD_input.setText("1");
}
if (pipeOD_input.getText().toString().length() == 0) {
pipeOD_input.setText("1");
}
if (pipe_length_input.getText().toString().length() == 0) {
pipe_length_input.setText("1");
}
if (drive_length_input.getText().toString().length() == 0) {
drive_length_input.setText("1");
}
if (muck_up_input.getText().toString().length() == 0) {
muck_up_input.setText("2.5");
}
if (jacking_speed_input.getText().toString().length() == 0) {
jacking_speed_input.setText("1");
}
double pi = Math.PI / 4;
double tbmODInput = Double.parseDouble(machineOD_input.getText().toString()) / 1000.0;
double pipeODInput = Double.parseDouble(pipeOD_input.getText().toString()) / 1000.0;
double muckUpInput = Double.parseDouble(muck_up_input.getText().toString());
double jackingSpeedInput = Double.parseDouble(jacking_speed_input.getText().toString());
double pipeLengthInput = Double.parseDouble(pipe_length_input.getText().toString());
double driveLengthInput = Double.parseDouble(drive_length_input.getText().toString());
// Calculate Volume per Meter (Ltr per meter)
double sum = ((pi * (tbmODInput) * (tbmODInput)) - (pi * (pipeODInput) * (pipeODInput))) * muckUpInput * 1000;
litre_per_meter_result.setText(String.format("%.0f", sum));
// Calculate Lubrication Pump Capacity (Ltr per min)
double sum2 = (jackingSpeedInput / 1000) * sum;
lub_result.setText(String.format("%.0f", sum2));
// Calculate Volume per pipe (M³ per pipe)
double sum3 = (sum / 1000) * pipeLengthInput;
volume_per_pipe_result.setText(String.format("%.3f", sum3));
// Calculate Volume for drive (M³ for drive)
double sum4 = (sum / 1000) * driveLengthInput;
volume_for_drive_result.setText(String.format("%.0f", sum4));
saveData();
});
machineOD_input.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (machineOD_input.getText().toString().length() > 0) {
machineOD_input.setText("");
}
}
});
loadData();
updateViews();
}
public void saveData(){
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(TBMODINPUT, machineOD_input.getText().toString());
editor.putString(PIPEODINPUT, pipeOD_input.getText().toString());
editor.putString(PIPELENGTHINPUT, pipe_length_input.getText().toString());
editor.putString(DRIVELENGTHINPUT, drive_length_input.getText().toString());
editor.putString(MUCKUPINPUT, muck_up_input.getText().toString());
editor.putString(JACKINGSPEEDINPUT, jacking_speed_input.getText().toString());
editor.apply();
}
public void loadData(){
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
tbmODinputText = sharedPreferences.getString(TBMODINPUT, "");
pipeODinputText = sharedPreferences.getString(PIPEODINPUT, "");
pipeLengthinputText = sharedPreferences.getString(PIPELENGTHINPUT, "");
driveLengthinputText = sharedPreferences.getString(DRIVELENGTHINPUT, "");
muckupinputText = sharedPreferences.getString(MUCKUPINPUT, "");
jackingSpeedinputText = sharedPreferences.getString(JACKINGSPEEDINPUT, "");
}
public void updateViews(){
machineOD_input.setText(tbmODinputText);
pipeOD_input.setText(pipeODinputText);
pipe_length_input.setText(pipeLengthinputText);
drive_length_input.setText(driveLengthinputText);
muck_up_input.setText(muckupinputText);
jacking_speed_input.setText(jackingSpeedinputText);
}
}
machineOD_input.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (machineOD_input.getText().toString().length() > 0) { machineOD_input.setText(""); } } });
– user2253720 Oct 26 '21 at 07:28