JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 526 forks source link

How to get IconTextView text programatically? #90

Closed oscar-urbina-tech closed 9 years ago

oscar-urbina-tech commented 9 years ago

Hope you can help, I have a xml resource file with a IconTextView:

< android.widget.IconTextView android:id="@+id/article_item_like" android:layout_width="wrap_content" android:layout_height="wrap_content" android:shadowColor="#22000000" android:shadowDx="3" android:shadowDy="3" android:shadowRadius="1" android:text="{fa-heart}" android:textColor="#FF33B5E5" android:textSize="30sp" />

In order to complete a feature, i need to get the value of that item. But when i try to get the value:

Log.i("MyTag", "This is the text:" + myIconTextView.getText().toString());

I just get a strange char in console. Is there a way to get this value? pe. Get "{fa-heart}".

Thanks!

JoanZapata commented 9 years ago

You can't do it out of the box, I don't think it's a common usecase so I won't support it. However it shouldn't be too hard to get the name back by iterating over IconValue.values() and compare them with the "strange char" until you find a match.

oscar-urbina-tech commented 9 years ago

Ok, Thanks! :D

Julienpraad commented 8 years ago

First thank you for your really great library. However, you should really take into consideration the situation when the user has to compare the text. I faced this problem today and was not able to overcome it.

JoanZapata commented 8 years ago

@Julienpraad What do you compare the text with?

Julienpraad commented 8 years ago

For example View.getText().toString().equalIgnoreCase("{fa-heart 18sp}") is always evaluating to false even though the text of your text view is the same

JoanZapata commented 8 years ago

I see what you mean. There's a solution for that but it would be a breaking change.

May I ask why you need to compare the text to this?

Julienpraad commented 8 years ago

Oh I needed to change the symbol of the text when the user click on it so that a filled heart is replaced by an outlined one for example and vice versa in a recycler view grid so I won't need to add extra object fields to use them for checking purposes

tenam24 commented 7 years ago

It would be great to have a method to return the text, for example, "{ion-chevron-up}" so that I could validate the icon has changed to "{ion-chevron-down}" once it clicked in my Espresso automated test case.