Hi All,
I have a simple fragment inside I have
EditText. I'm trying to set the EditText setText
onCreateView,
onResume and
onStart but I couldn't get the text to show.
setHint works just fine unlike setText. any idea what could be the reason?
Thanks in advance!!
What I have tried:
XML:
EditText is inside
ScrollView
<EditText
android:id="@+id/output_value"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="3"
android:hint="@string/output_function_value_hint"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:saveEnabled="false"/>
onCreateView:
private View rootView;
private EditText outputEditText;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_io,container,false);
outputEditText = rootView.findViewById(R.id.output_value);
outputEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void afterTextChanged(Editable s) {
if(!TextUtils.isEmpty(s.toString())){
try{
if(Integer.valueOf(outputEditText.getText().toString()) > MAX_OUTPUT_VALUE || Integer.valueOf(outputEditText.getText().toString()) <MIN_OUTPUT_VALUE ){
Toast.makeText(getSmartControlActivity(), getString(R.string.output_function_value_hint),Toast.LENGTH_SHORT).show();
outputEditText.setText("");
}
}catch(NumberFormatException ex){
ex.printStackTrace();
outputEditText.setText("");
}
}
}
});
return rootView;
}
Trying to setText onResume or onStart with no luck
@Override
public void onResume() {
super.onResume();
outputEditText.setText("42");
}
@Override
public void onStart(){
super.onStart();
outputEditText.setText("42");
}