0

I am using a ListFragment to display tweets from Twitter by HashTags.

The code for displaying tweets from Twitter is simply

final SearchTimeline searchTimeline = new SearchTimeline.Builder()
            .query(mHashtags)
            .build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity())
            .setTimeline(searchTimeline)
            .build();
    setListAdapter(adapter);

I need to allow my users to change the hashtags dynamically; that is, they may make a search for #thingOne and then after viewing the results make a search for #TwoThings. How do I accomplish this? When I try to call setListAdapter with a new adapter, I can an exception (which really does not make sense to me, as I am not really changing anything except a new instance of the same adapter)

java.lang.ClassCastException: android.support.v4.view.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

So does the Twitter Fabric api provides a way for changing the SearchTimeline for an adapter? If not, is there a way for replacing the adapter for a ListFragment?

learner
  • 11,490
  • 26
  • 97
  • 169

1 Answers1

0

Starting with TweetUi 1.2.0 (which comes with Twitter 1.5.0 and higher), TweetTimelineListAdapters include a refresh method which will delete the Tweets in the adapter and make a request for the latest Tweets. refresh(Callback<TimelineResult<T>> cb) takes a callback which you can use to handle the request's success or failure. From the success callback, you get access to the latest Tweets loaded, though they're automatically added to the adapter, you don't need to take action on them.

If you're interested in creating a "pull to refresh" style UI, you can see the sample app.

Courtesy : https://twittercommunity.com/t/how-to-update-user-timeline-with-latest-tweets-from-twitter/38307

See the documentation also.

Checkout this

Anoop M Maddasseri
  • 10,213
  • 3
  • 52
  • 73
  • Thanks for replying. But the answer missed the question. I am aware of the refresh callback. The question is about issuing a new search entirely. The first search may have been about `#apples` and the second search maybe be about `#beds`. Thanks again. Do you know how to do what I just described? – learner Oct 29 '15 at 06:48