Android : Build Tweet with static JSON

android

#1

Hello there,
I’m currently working on integrating Twitter in my Android app after successfully doing it in my iOS app. Under iOS there is a simple and powerful static method which helps to build a “Tweet” instance from JSON data without any call to the twitter API. I’ve searched how to do proceed the same way with Android but it seems there is no such method. The only solution seems to give the tweet IDs and then load them which I dont want to do because I already have all the required json result from my server.

Do you know how can I do this ? Build a Tweet instance by injecting my json ?

Thanks !


#2

Hi @adrien, On Android you can use GSON to convert JSON to a Tweet object. That object can then be passed to the appropriate constructor on TweetView or CompactTweetView. There is also a setter called setTweet(Tweet tweet).

final Tweet tweet = gson.fromJson("JSON_STRING", Tweet.class);
final TweetView tweetView = new TweetView(context, tweet);

#3

Hello @EricoFrohnhoefer. Thank you so much for your answer ! Nice and clean solution. I’m pretty new to Android :slightly_smiling:
Will try this as soon as I will have so spare time. Thanks !


#4