Editable insert - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Editable insert method.

This code example shows how to use the following methods:insert
  @Override 
  public boolean onKey(View v, int keyCode, KeyEvent event) {
    Editable text=editor.getText();
 
    if (keyCode == KeyEvent.KEYCODE_TAB) {
      text.insert(editor.getSelectionStart(), "\t");
    } 
    else if (event.isCtrlPressed()) {
      int rawStart=editor.getSelectionStart();
      int rawEnd=editor.getSelectionEnd();
      int selStart=(rawStart>rawEnd ? rawEnd : rawStart);
      int selEnd=(rawStart>rawEnd ? rawStart : rawEnd);
       
      switch (keyCode) {
        case KeyEvent.KEYCODE_T:
          Toast.makeText(this,
                         TextUtils.substring(text, selStart, selEnd),
                         Toast.LENGTH_LONG).show();
 
          return(true); 
6
CodeRank
This code example shows how to use the following methods:append, insert, setSpan, length, toString
            handleListTag(output);
    } 
 
    private void handleListTag(Editable output) {
        if (mListParents.lastElement().equals("ul")) {
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;
            output.setSpan(new BulletSpan(15 * mListParents.size()), start,
                    output.length(), 0);
        } else if (mListParents.lastElement().equals("ol")) {
            mListItemCount++;
 
            output.append("\n");
            String[] split = output.toString().split("\n");
 
            int lastIndex = split.length - 1;
            int start = output.length() - split[lastIndex].length() - 1;

7
CodeRank
This code example shows how to use the following methods:clear, insert, length, toString
 
	@Override 
	public void afterTextChanged(Editable editable) {
 
		try { 
			if(editable.length() > 0){
				int value = Integer.parseInt(editable.toString());
				if(value < min) {
					editable.clear();
					editable.insert(0,String.valueOf(min));
				} 
				if(value > max){
					editable.clear();
					editable.insert(0,String.valueOf(max));
				} 
			} 
		} 
		catch (NumberFormatException e) {
			// the EditText this is applied to should have XML attributes such as 
			// android:inputType="number" 

6
CodeRank
This code example shows how to use the following methods:insert, replace, toString
	} 
 
	// Happens when the user clicks on the lists 
	@Override 
	public void onDialogListItemClick(String[] items, String item, int index) {
		String formVal = input.toString();
		int start = formVal.indexOf(item);
		int end = start + item.length()+1;
		input.replace(start, end, "");
		input.insert(start, DetailedFeedbackFragment.createTextTokenizer(items[index]));
	} 
 
	 
	// Happens when the user clicks on the bubbles 
	@Override 
	public void onUserInputSelected(View view, String item) {
		FeedbackDialog feedbackDialog = new FeedbackDialog();
		Log.d(getClass().toString(), item); 
		Bundle args = new Bundle();
		args.putString(FeedbackDialog.CHOSEN_ADJECTIVE, item);
5
CodeRank
This code example shows how to use the following methods:insert
	private void open(){ 
		if (showing) return;
		Editable ed = (Editable)textView.getText();
		pos = ((Spannable) ed).getSpanEnd(this);
		 
		ed.insert(pos, text);
		((Spannable) ed).setSpan(quoteSpan, pos, pos + text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		showing = true;
	} 
	 
	private void close(){ 
		if (!showing) return;
		for (SpoilerSpan s :spoilerSpanList){
			s.close();
		} 
		 
		Editable ed = (Editable)textView.getText();
		pos = ((Spannable) ed).getSpanEnd(this);
		 
		ed.removeSpan(quoteSpan);
5
CodeRank
This code example shows how to use the following methods:insert
	private void open(){ 
		if (showing) return;
		Editable ed = (Editable)textView.getText();
		pos = ((Spannable) ed).getSpanEnd(this);
		 
		ed.insert(pos, text);
		((Spannable) ed).setSpan(quoteSpan, pos, pos + text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		showing = true;
	} 
	 
	private void close(){ 
		if (!showing) return;
		for (SpoilerSpan s :spoilerSpanList){
			s.close();
		} 
		 
		Editable ed = (Editable)textView.getText();
		pos = ((Spannable) ed).getSpanEnd(this);
		 
		ed.removeSpan(quoteSpan);
4
CodeRank
This code example shows how to use the following methods:insert

Related Editable insert Questions & Answers:

insert Method Overview
Convenience for replace(where, where, text, start, end)
See Code Examples for other Android Editable Methods: