I have a simple issue (I hope).
I have two preset values (IP and port) that I need the app user to be able to change. I have two values in a class.
public class SoftOptions {
var RemoteHost: String = "192.168.43.237"
var RemotePort: Int = 1234
}
And then of course val mySettings = SoftOptions().
I then show them in my MainActivity as text fields. Then, upon pushing the Settings button, I go to an activity called Settings. In it, I place the values to the edit boxes so as not to have to change the entire IP address if only the last digit changes. I have managed this too.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
var editEnterip = mySettings.RemoteHost
var editEnterport= mySettings.RemotePort
setContentView(R.layout.activity_settings)
this.editEnterip.setText(mySettings.RemoteHost.toString())
this.editEnterport.setText(mySettings.RemotePort.toString())
But then, in the button listener, I just need to read the new value and assign that to the mySettings.RemoteHost and mySettings.RemotePort variables.
btnSetip.setOnClickListener {
var finalIP =findViewById<EditText>(R.id.editEnterip)
Toast.makeText(this, finalIP.toString(), Toast.LENGTH_SHORT).show()
myTargetIP = finalIP.toString()
mySettings.RemoteHost = finalIP.toString()
editEnterport = editEnterport . toString () .toInt()
myTargetPort = "$editEnterport"
mySettings.RemotePort = myTargetPort.toString().toInt()
val intent = Intent(this, MainActivity::class.java)
intent.putExtra("myTargetIP", myTargetPort)
intent.putExtra("myTargetPort", myTargetPort)
startActivity(intent)
}
But this, while not crashing the app, puts a godawful error message as the value of the remote host, even if the edited IP value is fine.
So, my question is merely, what am I doing wrong to not get a clean text value out of the edit box?
This is the message in my user interface. And many thanks in advance, this forum is the most powerful of any I use.