Live editing of users input
By tagging android, I think you are discussing about android editText, is so you can do it by listening the TextChangedListener,
EDITED: for backspace
editText.addTextChangedListener(new TextWatcher() {
int len=0;
@Override
public void afterTextChanged(Editable s) {
String str = editText.getText().toString();
if(str.length()==4&& len <str.length()){//len check for backspace
editText.append("-");
}
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
String str = editText.getText().toString();
len = str.length();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
Real time updating of values on a form
If you want to display 'realtime' (meaningly, as the user types) values, you can use the keyup values :
- http://www.w3schools.com/jsref/event_onkeyup.asp
(for pure javascript) - http://api.jquery.com/keyup/ (for
jquery)
android edittext onchange listener
First, you can see if the user finished editing the text if the EditText
loses focus or if the user presses the done button (this depends on your implementation and on what fits the best for you).
Second, you can't get an EditText
instance within the TextWatcher
only if you have declared the EditText
as an instance object. Even though you shouldn't edit the EditText
within the TextWatcher
because it is not safe.
EDIT:
To be able to get the EditText
instance into your TextWatcher
implementation, you should try something like this:
public class YourClass extends Activity {
private EditText yourEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
yourEditText = (EditText) findViewById(R.id.yourEditTextId);
yourEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
// you can call or do what you want with your EditText here
// yourEditText...
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
}
}
Note that the above sample might have some errors but I just wanted to show you an example.
How do I add the ability to edit text within a react component?
So, first of all, I would encourage you not to switch between input
fields and div
s but rather to use a contenteditable div. Then you just use the onInput
attribute to call a setState
function, like this:
function Tasks ({item}) {
return(
<div className = 'tasks-container'>
<div contenteditable="true" onInput={e => editTask(item.id, e.currentTarget.textContent)} >
{item.chore}
</div>
</div>
)
}
Then, in the parent component, you can define editTask
to be a function that find an item by its id and replaces it with the new content (in a copy of the original tasks array, not the original array itself.
Additionally, you should avoid renaming the variable between components. (listOfTasks
-> jobItems
). This adds needless overhead, and you'll inevitably get confused at some point which variable is connected to which. Instead say, <MyComponent jobItems={jobItems} >
or if you want to allow for greater abstraction <MyComponent items={jobItems} >
and then you can reuse the component for listable items other than jobs.
How to make EditText observe a ViewModel's LiveData and forward user input to the ViewModel without using data binding
I also ran into this problem since I don't like the databinding library. I did as @kAliert said, but in my ViewModel
to keep the logic there. I just added a simple catch on the function that receives my text changes events in the ViewModel
. It works well.
fun editTextChanged(newText: String) {
if (newText == textLiveData.value) {
return
}
}
Related Topics
Navigationview Menu Items with Counter on the Right
Choosing Photo Using New Google Photos App Is Broken
How to Get the Current Location in Google Maps Android API V2
Android.View.View.Systemuivisibility Deprecated. What Is the Replacement
Camera Preview Image Data Processing with Android L and Camera2 API
How to Know That My Webview Is Loaded 100%
How to Get Phone Number from an Incoming Call
Load an Image from Assets Folder
Android Studio 3.0 Execution Failed for Task: Unable to Merge Dex
Add Custom Font for Complete Android Application
Confusion on Yuv Nv21 Conversion to Rgb
Wrong Requestcode in Onactivityresult
Custom Seekbar (Thumb Size, Color and Background)
How to Resize Image (Bitmap) to a Given Size
What Method Should I Use Now Since Firebaseinstanceid.Getinstance().Gettoken() Is Deprecated
How to Add Image in Expandable List in Parent in Android