Grab Tweet string value using Fabric for android

android
fabric

#1

I am working on an android app and I am new to the Fabric API.

I am trying to grab the string values of the tweets. I can populate a ListActivity with all the tweets(code taken from the documentation examples), but cannot figure out how to access that list to get the string values or even the tweet ids.

When i do this:

Log.d("", adapter.getItem(1).toString());
or

Log.d("", adapter.getItem(1));

it tells me “Invalid Index 1, size is 0”

any help would be much appreciated!

Thanks


#2

Can you post more code? The size will be zero if the timeline hasn’t finished loading.


#3

Hey thanks for your reply!

this is the code I’m using:

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;

import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class TwitterFeed extends ListActivity {
    TweetTimelineListAdapter test;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
        String username = pref.getString("username", "NULL");
        super.onCreate(savedInstanceState);

        final UserTimeline userTimeline = new UserTimeline.Builder()
        .screenName(username).includeReplies(true).includeRetweets(true)
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
                .setTimeline(userTimeline)
                .build();
        setListAdapter(adapter);
    }
    @Override
    protected void onResume(){
        super.onResume();
        Log.d("ListItem", adapter.getItem(1).toString());
    }
}

#4

Likely the list hasn’t been loaded yet. Something like this belongs in a click handler. Maybe if you explain your use case better I can be more helpful.


#5

My ultimate goal is to store the 140 character tweets (not the ids) in an accesible list/array/database.

You were right, the list was not loaded yet. I created a custom array adapter that extends theTweetTimelineListAdapter, and was able to get the tweet ids. Now it is a matter of turning those Ids into the actual tweets themself. I am not sure how to accomplish that yet. Any ideas?

Again, thank you for your reply.