问题
I have a field filled with an EditText control, it figures: 475759403048575663648495004945757590.
What can I use to choose the first 10 numbers from this EditText:
and then, insert the numbers 4757594030, in the TextView?
回答1:
You can substring the string to 10 characters.
String s = somestring.substring(0,10);
So this will return the first 10 characters, and now you can put the value S in your control!
回答2:
You can put a textwatcher to the edittext, then count as the edit text is being edited, when you get to the number of characters (10 in this case), you can then display those characters.
Example
TextView textView = ....
edittext.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 textVal) {
String inputText = textVal.toString();
if (inputText.length() == 10) {
textView.setText(inputText);
}
}
});
来源:https://stackoverflow.com/questions/22143416/how-can-i-get-the-first-10-digits-from-edittext-and-set-this-digits-in-a-textvi