Search code examples
javaandroidtextviewpreview

How do i preview a TextView?


Good day,

I am trying to add a textview preview to my app. For example, i created a news app with card view and I want to have a few lines on the first screen and then it expands the full story in a new activity onclick.

I have already set up the new activity part but I just need the preview on the first screen


Solution

  • You should have all the News data available on your first Activity - NewsActivity. In that case you just

    1. Limit number of lines of preview TextView with attribute android:maxLines="3"
    2. Then on click on TextView you would open another activity with an Intent and inside the Intent pass whole News object that corresponds to data displayed in preview TextView. Remember that News object should be implement Serializable or Parcelable interfaces to be passed with intent.
    3. Retrieve data from an Intent and display it in the second Activity - NewsDetailsActivity