How to remove character from edittext?

I want to know if there is any method with which I can remove a specific character from EditText. I want to remove the charter from EditText, indicating the position in the text editor is there something like removeAt()for EditText?

    public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final Button b1=(Button)findViewById(R.id.button1);
        final EditText ed1=(EditText)findViewById(R.id.editText1);
        b1.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub

             //i want something like this
                    ed1.removeAt(5);
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }


}

ADDITIONAL INFORMATION

The main problem is that I want to make the text bold inside the edittext, but not all the text. Text typed after turning on the bold button (bold is my toggle button). ok here is the code

     ed1.setOnKeyListener(new OnKeyListener() {

        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // TODO Auto-generated method stub
            int i = 0;

            switch(event.getAction())
            {
            case KeyEvent.ACTION_UP:
                    if(bold.isChecked())
                    {
                         i=ed1.getSelectionStart();

                         ed1.append(Html.fromHtml("<b>"+ed1.getText().toString().charAt(i-1)+"</b>"));

                    }
                    return true;

            }
            return false;
        }
    });

the problem is that I get a double character, which is a normal character, and then bold again, so I want to remove normal characters by indicating the position there

+5
source share
4 answers

, getText , :

int charIndex;
String text = ed1.getText().toString();
text = text.substring(0, charIndex) + text.substring(charIndex+1);
ed1.setText(text);

BOLD :

ed1.setText((Spanned)ed1.getText().delete(indexStart , indexEnd));

"indexStart" "indexEnd -1". delete (0,1); .

, :)

+7

. ,

int cursorPosition = mDialerEditText.getSelectionStart();
    if (cursorPosition > 0) {
          mDialerEditText.setText(mDialerEditText.getText().delete(cursorPosition - 1, cursorPosition));
        mDialerEditText.setSelection(cursorPosition-1);
    }
+2

EditText TextView, . getText(), String, char setText(str) EditText, .

+1

EditText String.

String temp = ed1.getText().toString();

Now manipulate this String temp to remove the character in the right place. (I suggest you use a function String.substring(..)to achieve this.)

Finally, set the temp temp parameter to EditText.

ed1.setText(temp);
0
source

All Articles