Fairly new so sorry for the stupid question.. I'm trying to update the TextView as soon as the EditText loses focus. The Edittext needs to convert to an int to calculate what the textview should show. As soon as the EditText loses focus the app crashes.
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText strScore = (EditText) findViewById(R.id.strScore);
final TextView strMod = findViewById(R.id.strMod);
strScore.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View strScoreView, boolean hasFocus) {
if (!hasFocus){
updateModifier(strMod,strScore);
}
}
});
}
private void updateModifier(TextView modifier, EditText score){
int scoreInt = Integer.parseInt(score.getText().toString());
int modifierInt = scoreInt - 10 / 2;
modifier.setText(modifierInt);
}
}