TextView getText - top ranked examples from Open Source projects

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

This code example shows how to use the following methods:getText, setText
        context = new Activity();
    } 
 
    @Test 
    public void shouldBeAbleToGetTextFromTextViewAfterUsingSetTextWithHtmlDotFromHtml() throws Exception { 
        TextView textView = new TextView(context);
        textView.setText(Html.fromHtml("<b>some</b> html text"));
        assertThat(textView.getText().toString()).isEqualTo("<b>some</b> html text");
    } 
 
    @Test 
    public void shouldBeAbleToGetTextFromEditTextAfterUsingSetTextWithHtmlDotFromHtml() throws Exception { 
        EditText editText = new EditText(context);
        editText.setText(Html.fromHtml("<b>some</b> html text"));
        assertThat(editText.getText().toString()).isEqualTo("<b>some</b> html text");
    } 
 
    @Test(expected = NullPointerException.class) 
    public void shouldThrowNullPointerExceptionWhenNullStringEncountered() throws Exception { 
        Html.fromHtml(null);
8
CodeRank
This code example shows how to use the following methods:getLinksClickable, getText, setMovementMethod, setText
    private ListViewTool() { 
    } 
 
 
    public static void addLinks(TextView view) {
        CharSequence content = view.getText();
        view.setText(convertNormalStringToSpannableString(content.toString()));
        if (view.getLinksClickable()) {
            view.setMovementMethod(LongClickableLinkMovementMethod.getInstance());
        } 
    } 
 
    private static SpannableString convertNormalStringToSpannableString(String txt) {
        //hack to fix android imagespan bug,see http://stackoverflow.com/questions/3253148/imagespan-is-cut-off-incorrectly-aligned 
        //if string only contains emotion tags,add a empty char to the end 
        String hackTxt;
        if (txt.startsWith("[") && txt.endsWith("]")) {
            hackTxt = txt + " ";
        } else { 
            hackTxt = txt;
8
CodeRank
This code example shows how to use the following methods:getWindowToken, getText, setText
  } 
 
  @Override 
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (event == null || event.getAction() == KeyEvent.ACTION_UP) {
      adapter.add(v.getText().toString());
      v.setText("");
 
      InputMethodManager imm=
          (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
 
      imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
    } 
 
    return(true); 
  } 
 
  private void configureActionItem(Menu menu) {
    EditText add=
        (EditText)menu.findItem(R.id.add).getActionView()
8
CodeRank
This code example shows how to use the following methods:addLinks, getText, setLinkTextColor
        notesPreview.setVisibility(TextUtils.isEmpty(textToUse) ? View.GONE : View.VISIBLE);
        linkifyDisplayView(); 
    } 
 
    private void linkifyDisplayView() { 
        if(!TextUtils.isEmpty(notesPreview.getText())) {
            notesPreview.setLinkTextColor(Color.rgb(100, 160, 255));
            Linkify.addLinks(notesPreview, Linkify.ALL);
        } 
    } 
 
    @Override 
    protected void afterInflate() { 
        editText = (EditText) getView().findViewById(R.id.notes);
        notesPreview = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
    } 
 
    @Override 
    protected void additionalDialogSetup() { 
        super.additionalDialogSetup(); 
8
CodeRank
This code example shows how to use the following methods:getText, setText
    shaker.close();
  } 
   
  public void shakingStarted() { 
    Log.d("ShakerDemo", "Shaking started!");
    transcript.setText(transcript.getText().toString()+"Shaking started\n");
    scroll.fullScroll(View.FOCUS_DOWN);
  } 
   
  public void shakingStopped() { 
    Log.d("ShakerDemo", "Shaking stopped!");
    transcript.setText(transcript.getText().toString()+"Shaking stopped\n");
    scroll.fullScroll(View.FOCUS_DOWN);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:getVisibility, getText
   * <p/> 
   * Robolectric extension. 
   */ 
  @Override 
  public String innerText() {
    CharSequence text = realTextView.getText();
    return (text == null || realTextView.getVisibility() != View.VISIBLE) ? "" : text.toString();
  } 
 
  public int getTextAppearanceId() { 
    return textAppearanceId;
  } 
 
  @Implementation 
  public void addTextChangedListener(TextWatcher watcher) {
    this.watchers.add(watcher);
    directlyOn(realTextView, TextView.class).addTextChangedListener(watcher);
  } 
 
  @Implementation 
7
CodeRank
This code example shows how to use the following methods:getText, getTextColors, getTextSize
 
            new NotificationViewSearcher(n, context, new Predicate<View>() {
                public boolean apply(View view) {
                    if (view instanceof TextView) {
                        TextView tv = (TextView) view;
                        if (tv.getText().toString().startsWith(TEXT_SEARCH_PREFIX)) {
                            int textColour = tv.getTextColors().getDefaultColor();
                            TextAppearance appearance = new TextAppearance(textColour, tv.getTextSize()/displayMetrics.scaledDensity);
 
                            if (TEXT_SEARCH_TEXT.equals(tv.getText().toString())) {
                                textAppearance = appearance;
                            } else { 
                                titleAppearance = appearance;
                            } 
                            return !needToSearch(); 
                        } 
                    } 
                    return false; 
                } 
            }).search(); 
8
CodeRank
This code example shows how to use the following methods:setLayoutParams, getText, length, setText, setTextColor
        lp.topMargin = 10;
        iv.setLayoutParams(lp);
         
         
        // Add label: 
        TextView tv = new TextView(this);
        lp = new LinearLayout.LayoutParams(
        		85, 
        		35); 
        lp.bottomMargin = 6;
        tv.setLayoutParams(lp);
         
        tv.setText(info.activityInfo.loadLabel(getPackageManager()));
        tv.setTextColor(Color.BLACK);
        tv.setTextSize(15);
         
        // First convert text to 'spannable' 
		tv.setText(tv.getText(), TextView.BufferType.SPANNABLE);
		Spannable str = (Spannable) tv.getText();
		 

7
CodeRank
This code example shows how to use the following methods:getMovementMethod, getText, setMovementMethod, setText
		void onClick(); 
	} 
 
	public static void clickify(TextView view, final String clickableText, final MyClickableSpan.OnClickListener listener) {
 
		CharSequence text = view.getText();
		String string = text.toString();
		MyClickableSpan span = new MyClickableSpan(listener);
 
		int start = string.indexOf(clickableText);
		int end = start + clickableText.length();
		if (start == -1)
			return; 
 
		if (text instanceof Spannable) {
			((Spannable) text).setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		} else { 
			SpannableString s = SpannableString.valueOf(text);
			s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
			view.setText(s);

7
CodeRank
This code example shows how to use the following methods:getText, setText
            } 
        } 
    } 
 
    void log(String s) {
        mLog.setText(mLog.getText() + "\n" + mDateFormat.format(new Date()) + ": " + s);
    } 
 
    BroadcastReceiver mReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) { 
            String action = intent.getAction(); 
            String title = action; 
            int index = title.lastIndexOf('.'); 
            if (index >= 0) { 
                title = title.substring(index + 1); 
            } 
            if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { 
                int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); 
                log(title + ": level=" + level); 
            } else { 
7
CodeRank

Related TextView getText Questions & Answers:

Other TextView getText Examples

49:	
50:	  public void onClick(View view) {
51:	    String string = button.getText().toString();
52:	    int hitTarget = Integer.valueOf(string) + 1;
53:	    button.setText(String.valueOf(hitTarget));

Read More

57:				@Override
58:				public void onClick(View v) {
59:					if (txtCategory.getText().toString().trim().length() > 0) {
60:						
61:						// new category name
-
60:						
61:						// new category name
62:						String newCategory = txtCategory.getText().toString();
63:	
64:						// Call Async task to create new category

Read More

32:				@Override
33:				public void onClick(View v) {
34:					if (txtCategory.getText().toString().trim().length() > 0) {
35:						
36:						// new category name
-
35:						
36:						// new category name
37:						String newCategory = txtCategory.getText().toString();
38:	
39:						// Call Async task to create new category

Read More

getText Method Overview
Return the text the TextView is displaying.
See Code Examples for other Android TextView Methods: