• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How can I limit number of words in my textview?

 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is the code which I have written . I am using a textView in my xml I simple want first two words to appear in textview  which is coming with data binding in variable "viewModel.option.name" at after those two words I want at the end "..." should appear.And I want these two words to appear in different lines.
For eg: If "viewModel.option.name" is having value  "Chocolate ice cake" so I want text view should show "Chocolate ice ..."  and also want chocolate and ice to be in different lines.Any idea how to achieve it.I have tried my best still not able to succeed .
 
Saloon Keeper
Posts: 5809
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried?

You can set the contents programmatically when the view is created instead of having it done by the ViewModel.
 
priyanshi bhardwaj
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What have you tried?

I have tried using ellipsized but I can't see any last three dots in my text .And how can I limit words in text view  from xml side?
 
Tim Moores
Saloon Keeper
Posts: 5809
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have tried using ellipsized but I can't see any last three dots in my text .


How, exactly, did you do that? Show the code.

And how can I limit words in text view  from xml side?


You can't - there's no concept of words, only characters.
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!