How to make EditText
accept input in format:
4digit 4digit 4digit 4digit
I tried Custom format edit text input android to acc
If anyone still looking for answer,
Try the format-edit-text library for auto-formatting text in one line of code. This library uses dash(es) to define the format of the input.
editText.setFormat("any (dash) format");
add format-edit-text library dependency in app/build.gradle
implementation 'com.androidwidgets:formatedittext:0.2.0'
Add FormatEditText view in activity_main.xml
Set credit-card format to FormatEditText view in MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final FormatEditText editText1 = findViewById(R.id.edit_text_1);
editText1.setFormat("---- ---- ---- ----");
}
}
This will produce the below output
PS: Make sure parameter inputType is added to the FormatEditText view in the layout file.
android:inputType="number"