I want to use an EditText for the input from Barcode Scanners.
The Barcode Scanner acts like a physical Keyboard.
I scan a Barcode
It types the Barcode like an external Keyboard with a enter at the end
I have an EditText which should always be focused but never show the
software keyboard. I don't want to deactivate the Keyboard completely because it's needed in the same Class on a different EditText.
<EditText
android:id="#+id/barcodeText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:ems="10"
android:singleLine="true"
android:cursorVisible="false"
android:gravity="center"
android:background="#00000000"
android:textColor="#color/secondary_text"
>
then use TextChange Listener for your Edittext. Like this
editText.setInputType(InputType.TYPE_NULL);
editText.requestFocus();
editText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {}
#Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if(s.length() != 0)
// Your action
}
});
Please try with this property
android:inputType="none"
Related
I want to display the text that the user enters in an EditText in a TextView.
As the user starts typing, the value of the TextView should change.
eg: If the user types a the value of the TextView should be changed to a and then he types b after that, the value of the TextView should be changed to ab...
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"/>
This is the xml I'm using.
So is there anything like a edittext.setOnTypeListener so that I can add the textView's text directly
You can use a text change listener for this purpose.
Do it like this.
edittext.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {}
#Override
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start,
yourTextView.setText(s.toString());
});
You may use it according to your convenience in the before,after or onTextChanged method.
I am using Kotlin. I have used gravity right so that input number start from right. But EditText cursor keep stay always left of the input text in EditText. I want to keep gravity right & text right to left.Here is the image
Here is my EditText xml code..
<EditText
android:id="#+id/et_amount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:ellipsize="end"
android:gravity="right|center_horizontal|center_vertical"
android:textStyle="bold"
android:maxLength="6" >
<requestFocus />
</EditText>
Please help me so that input text start from left to right & cursor show always right.
Try to add this to your edittext:
android:textDirection="rtl"
try this:
EditText text = new EditText(context);
text.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 text1 = text.getText().toString();
text.setText(text1);
text.setSelection(text1.length());
}
});
it will be work;
hope to help you
I have an EditText in my app with textChangeListener that convert number format on afterTextChanged.
this is my EditText in layout file:
<EditText
android:id="#+id/zone_name"
android:layout_width="250dp"
android:layout_height="match_parent"
android:background="#drawable/margin_shape_table"
android:paddingStart="8sp"
android:paddingEnd="8sp"
android:singleLine="true"
android:inputType="text"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
and this is my listener code:
zoneName.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
String char1 = s.toString();
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
if (s.length() > 0){
zoneName.removeTextChangedListener(this);
zoneName.setText(converter.convertNumbers(s.toString()));
zoneName.addTextChangedListener(this);
zoneName.setSelection(s.length());
}else {
zoneName.setText("");
}
}
});
The problem is that when I run it on Asus ZenPad8.0 (android 6.0.1) it only get first entered character and after that "Editable s" contains only first character.
I have this problem on this device only and for other devices it gets full entered text.
Anyone have any suggestion how to solve this problem?
the bug is with the Asus ZenUI's keyboard and you may add android:inputType="textNoSuggestions" to avoid the issue.
for more complete answer please check my answer to another question
https://stackoverflow.com/a/55933884/3880796
I have an EditText set up for user input. As soon as the user types any character I want that to trigger a floating label to rise above the EditText line. What is best method to see when user has typed in the first character on the EditText line? TextWatcher? Others?
partial Activity file:
...
private ListenerEditText cListenerEditText;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cardviewinput);
cListenerEditText = (ListenerEditText) findViewById(R.id.CEditText);
cTextInputLayout = (TextInputLayout) findViewById(R.id.ToDo_text_input_layout);
cListenerEditText.requestFocus();
cListenerEditText.setHint("To Do");
partial layout xml file:
...
<android.support.design.widget.TextInputLayout
android:id="#+id/ToDo_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.example.jdw.fourthscreen.ListenerEditText
android:id="#+id/CEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text|textCapSentences|textNoSuggestions"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textColorHighlight="#30D5C8"
android:singleLine="true"
android:maxLength="51"
android:imeOptions="actionNext|flagNoExtractUi"
android:layout_marginBottom="3dp"
android:nextFocusDown="#+id/DEditText" >
</com.example.jdw.fourthscreen.ListenerEditText>
</android.support.design.widget.TextInputLayout>
To monitor and/or control text input, we usually use TextWatcher or InputFilter.
For your case, I believe TextWatcher is the right way to do.
To monitor user typing event in EditText you can use TextWatcher.
You can use afterTextChanged() method to check every typed character.
Below is code for adding TextWatcher to EditText.
cListenerEditText.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) {
Log.e("TextWatcherTest", "afterTextChanged:\t" +s.toString());
}
});
I am using EditText and providing some Hint there. I am putting it like this:
android:hint="#string/user_name_hint"
android:textColorHint="#ffffff"
android:gravity="left"
But here hint is coming in the left side. But i want the hint is in the middle of the box and when i am clicking the text should start from the left.
How it is possible??
Use this EditText
<EditText
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:hint="user_name_hint"
android:textColorHint="#fffff"
android:gravity="center_horizontal"
android:id="#+id/editText1"/>
Then you need to add addTextChangedListener to solve your problem.
final EditText hintText = (EditText) findViewById(R.id.editText1);
hintText.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 (s.length() == 0) {
hintText.setGravity(Gravity.CENTER);
} else {
hintText.setGravity(Gravity.LEFT);
}
}
});
set Gravity to center.. android:gravity="center_horizontal"
Not sure you can do it in a "straight forward way". Probably some workaround - either suggested by nagesh or by placing a button on top of the edit text and switching to edit text when it gets clicked or focused