2

I have an EditText in which I want each paragraph to start with a bullet. The EditText itself goes to infinity, so to speak; which means a user can enter as many paragraphs as desired. So how do I get each paragraph to start with a bullet and keep the entire paragraph indented?

Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • Look here may be it will help you http://stackoverflow.com/questions/8280528/how-to-create-a-empty-bullet-paragraph-by-bulletspan – Mohamed Feb 12 '15 at 15:30
  • @Mohamed I saw that answer, I didn't understand it. It seems to work when each paragraph has exactly 3 characters. In my case each paragraph can be as long or as short as it needs to be. – Katedral Pillon Feb 12 '15 at 15:34
  • Yes, there is only 3 words in the examples, so you can just adapt it. When you do line break in your edittext, you should implement onKeyListener and then you add a BulletSpan yourEditBox.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { // intercept the return key return true; } return false; } }); – Mohamed Feb 12 '15 at 15:39

1 Answers1

0

you probably can do it by using a TextWatcher. I did the same before to add a @ symbol before the username

editor.addTextChangedListener(new TextWatcher(){
   @Override
   public void afterTextChanged(Editable e) {
       // here you can change the text in the editor
       if(e.charAt(e.length()-1) == '\n') {
           // add the new char you need
           ... here ...
       }
   }

   @Override
   public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
       { /* not action */ }

   @Override
   public void onTextChanged(CharSequence val, int arg1, int arg2, int arg3)
       { /* not action */ }
});
Budius
  • 39,391
  • 16
  • 102
  • 144