I have a listview which is build up of two textviews coming from a separate layout file. I use a BaseAdapter
to build the list from a JSON file.
I would like the first textview (Caption) to be clickable, if clicked that it shows the second textview (Text), and if clicked again that it hides it.
When I use an onClick
(android:onClick="ClText"
) I get an error. I think I should use something of an onClickListener
, but since I'm new to Android I'm not quite sure how to use it.
Can someone help me out with the code please?
You just need to set the onClickListener for the first item in the getView method of your adapter class that extends BaseAdapter. Here's an example to illustrate what you're trying to do.
If you just want to switch between two textview , you can simply use a ViewSwitcher. it allow you to switch between the view that are into it. You just have to call the nextView() method and this method is cycling, so you can call nextView() endlessly
You will be able to change the view that is display.
Then you can add the same onClickListener to these to textview write something like this :
Here is an example on how to use a click listener with java:
Honestly though, instead of changing the visibility of different textViews, why don't you just alter the TextView text? It would be much simpler and wouldn't require multiple TextViews.