Note that there are some explanatory texts on larger screens.

plurals
  1. POshow tweets in a listview in twitter4j
    primarykey
    data
    text
    <p>I have been playing around with twitter4j and Android and so far so good. However I am having problems figuring out how to display the tweets properly on a list View. Here is my code so far, based on the <a href="https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/timeline/GetHomeTimeline.java" rel="nofollow noreferrer">code example given on the Twitter4j website</a>:</p> <pre><code>public class MainActivity extends Activity { //ListView with the tweets private ListView timelineListView; // Alert Dialog Manager AlertDialogManager alert = new AlertDialogManager(); //Adapter ArrayAdapter&lt;twitter4j.Status&gt; tweetAdapter ; //List List&lt;Status&gt; rawStatuses; //Other stuff public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_main); //Login methods, checking that there is an Internet connection, etc... When a button is //pressed, an Asynctask is called and it retrieves the tweets: class updateTimeline extends AsyncTask &lt;Void, Void, Void&gt;{ protected void onPreExecute(Void thing){ } protected Void doInBackground(Void... arg0) { try { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken); User user = twitter.verifyCredentials(); rawStatuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (twitter4j.Status status : rawStatuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); //System.exit(-1); } return null; } protected void onPostExecute(Void result) { // dismiss the dialog after getting all products //pDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "Timeline updated", Toast.LENGTH_SHORT) .show(); tweetAdapter = new ArrayAdapter&lt;twitter4j.Status&gt;(MainActivity.this, android.R.layout.simple_list_item_1, rawStatuses); timelineListView.setAdapter(tweetAdapter); } }); } </code></pre> <p>It retrieves the last 20 tweets or so just fine. But my problems comes fromt he final part, where I bind the list rawStatuses to the adapter and the listView, because it basically prints ALL the information on screen:</p> <p><img src="https://i.stack.imgur.com/SfLDa.jpg" alt="tweets"></p> <p>Ok, not all that information is useful or ever needed, but it is there. And I don't know how to display in the listView only the Twitter handle and the tweet, for example (i.e. extract that information from the list rawStatuses properly). I thought about having a List with the most useful information (something like: <code>List &lt;User, Tweet, ID, Time&gt;</code> ), but it seems to me cumbersome and a very poor solution.</p> <p>My question is: How can or should manage all that information that a tweet contains (an many tweets) so I can display what I want and still have the rest? The closest answer I have found is <a href="https://stackoverflow.com/a/8883871/833937">this answer</a>, but the link given doesn't work anymore.</p> <p>I hope I have explained myself. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload