On Edittext when user type something i am adding "#" at last of line except for first line, also i add digits="1234567890#" to allow number only. Here is code
tt = new TextWatcher() {
public void afterTextChanged(Editable s){
}
public void beforeTextChanged(CharSequence s,int start,int count, int after){}
public void onTextChanged(CharSequence s, int start, int before, int count) {
inter.removeTextChangedListener(tt);
String[] lines = inter.getText().toString().
replace("#","").
split(System.getProperty("line.separator"));
StringBuilder str= new StringBuilder();
int row = 0;
for(String st : lines){
str.append(st+repeate("#",row)+System.getProperty("line.separator"));
row++;
}
inter.setText(str);
inter.addTextChangedListener(tt);
}
};
But the problem with this is when user type any thing its cursor move to start of line.
Also when user press del on softkeyboard while cursor is in between "#" it should remove last digit of that line and cursor should move to its near.
Please help.
EDIT
Now cursor work fine except backspace key
<EditText
android:id="@+id/inter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textSize="25sp"
android:paddingRight="50dp"
android:paddingTop="15dp"
android:paddingBottom="10dp"
android:digits="1234567890\n"
android:imeOptions="flagNoExtractUi"
/>
tt = new TextWatcher() {
int select =0;
public void afterTextChanged(Editable s){
inter.setSelection(select);
}
public void beforeTextChanged(CharSequence s,int start,int count, int after){
select = inter.getSelectionStart()+1;
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
inter.removeTextChangedListener(tt);
String[] lines = inter.getText().toString().
replace("#","").
split(System.getProperty("line.separator"));
StringBuilder str= new StringBuilder();
int row = 0;
for(String st : lines){
str.append(st+repeate("#",row)+System.getProperty("line.separator"));
row++;
}
inter.setText(str);
inter.addTextChangedListener(tt);
}
};
inter.addTextChangedListener(tt);