--ADVERTISEMENT--

In this tutorial, I am going to show how to link an android textview to another textview inside scrollview means when you click a TextView having some short content you will see long description in another text view below that TextView and when you click again the same text view, the description will be hidden.

To implement this in your android application you have to add little bit java and XML code in activity file and XML layout file.

Just we have to make visible the content of a TextView when users click the button or textview having short content and make invisible if the description textview is visible.

Related:
Android Text Links Using Linkify
Android Custom Vertical ScrollView Example
Android Menu - Handling Option Menu Item Click

Android Example: Show and Hide a TextView when Users Click Another TextView Inside ScrollView


Following is the content of java activity file and XML layout file to link a textview to another textview inside ScrollView.


XML Layout


Here I have added a ScrollView and four TextView. Two textview for short description and two for long description which will appear while clicking the button having short description.

res/layout/linking_textview_to_another_textview_inside_scrollview.xml

Java Activity File


In java activity file we control the textview when it is clicked. Making visible and invisible a text view when click another textview/ button. And I have used if else statement to make this.

src/ LinkingTextViewtoAnotherTextViewInsideScrollView.java

Strings.xml File


res/values/strings.xml

Android Example: Show and Hide a TextView when Users Click Another TextView Inside ScrollView

That’s all. Now run your Linking a TextView to Another TextView Inside ScrollView in Android application and click the textview having short description, another textview having long description will appear there.

Post a Comment

Powered by Blogger.