如何将 TextEdit 字段的输入保存到字符串中?
How to save input from TextEdit field into a string?
我正在制作一个简单的应用程序,其中有一个 TextInput 字段和旁边的一个按钮。
TextInput 字段从 strings.xml 加载 @string/duration_time。
它旁边的按钮将显示一条简单的消息("hello" + 字符串 duration_time)。但是,它将始终显示字符串 duration_time.
中的原始信息
如何设置 TextChangedListener 来更新 string/duration_time 以反映用户的输入?如何从 TextInput 访问信息并使用它?因为像下面的例子,在"public void afterTextChanged"下我试图保存信息,但我不知道它存储在哪里
亲切的问候
button2.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) {
}
@Override
public void afterTextChanged(Editable s) {
String duration_input= WHAT_Do_I_Put_Here;
}
});
假设您正在使用 editText 和按钮作为 Android Wigets。
现在,如果你想在点击 button.It 时获取 editText 中的文本,可以这样做
String textEdit = "";
button.setOnClickListener(->view{
textEdit = editText.getText().toString();
});
现在您的 textEdit 将包含您在 editText 中输入的文本。
我正在制作一个简单的应用程序,其中有一个 TextInput 字段和旁边的一个按钮。 TextInput 字段从 strings.xml 加载 @string/duration_time。 它旁边的按钮将显示一条简单的消息("hello" + 字符串 duration_time)。但是,它将始终显示字符串 duration_time.
中的原始信息如何设置 TextChangedListener 来更新 string/duration_time 以反映用户的输入?如何从 TextInput 访问信息并使用它?因为像下面的例子,在"public void afterTextChanged"下我试图保存信息,但我不知道它存储在哪里
亲切的问候
button2.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) {
}
@Override
public void afterTextChanged(Editable s) {
String duration_input= WHAT_Do_I_Put_Here;
}
});
假设您正在使用 editText 和按钮作为 Android Wigets。 现在,如果你想在点击 button.It 时获取 editText 中的文本,可以这样做
String textEdit = "";
button.setOnClickListener(->view{
textEdit = editText.getText().toString();
});
现在您的 textEdit 将包含您在 editText 中输入的文本。