android message is not posting on twitter - android

I am trying to post my message on twitter. When I click on button, it shows me message that your data has been posted on twitter,but when I check I don't get any message. Here is my code.
btnUpdateStatus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Call update status function
// Get the status from EditText
String status = txtUpdate.getText().toString();
new updateTwitterStatus().execute(status);
}
});
here is update twitterstatus class
private class updateTwitterStatus extends AsyncTask<String,Void,Void>
{
#Override
protected void onPreExecute()
{
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Updating to twitter...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
#Override
protected Void doInBackground(String... screen_name)
{
String status = null;
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);
// Update status
twitter4j.Status response = twitter.updateStatus(status);
Log.i(""+response, "value");
Log.d("Status", "> " + response.getText());
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
e.printStackTrace();
}
return null;
}
/// }
#Override
protected void onPostExecute(Void result)
{
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Status tweeted successfully", Toast.LENGTH_SHORT)
.show();
// Clearing EditText field
txtUpdate.setText("");
}
});
}
}
please help me. I am finding for this since a couple of days, I know I have asked this but I am not getting any appropriate solution, thankyou.

For twitter there are two libraries.
Twitter4j.jar (For text wall post)
Twitpick.jar (for picture post)
Either you can go for SocialAuth library (Well managed and simple to use)

Related

How to save a variable in AsyncTask in Android

I am using Twitter 4j to post tweet on single button. If user revoke access of my app then its showing Error in Logcat in do in background i want this error and if this error comes my another hide button of twitter authorize app visible. how do i do that please help. I need that error and if its exists i want to hide show my buttons.
class updateTwitterStatus extends AsyncTask<String, String, Void> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
protected Void doInBackground(String... args) {
String status = args[0];
try {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(consumerSecret);
String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, "");
String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, "");
AccessToken accessToken = new AccessToken(access_token, access_token_secret);
twitter4j.Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
StatusUpdate statusUpdate = new StatusUpdate(status);
File extStore = Environment.getExternalStoragePublicDirectory("/Twitter/Cache/demo.jpg");
statusUpdate.setMedia(extStore);
twitter4j.Status response = twitter.updateStatus(statusUpdate);
} catch (TwitterException e) {
Log.d("Failed to post!", e.getMessage());
error=e; //error is exception
}
return null;}
#Override
protected void onPostExecute(Void result) {
pDialog.dismiss();
Toast.makeText(getContext(), "Posted to Twitter!"+error, Toast.LENGTH_SHORT).show();
/* i need a variable like int a =10; access it globally, How i do that/*
} } }
You can save the exception in a variable and check it in onPostExecute()
and hide your button ..
new AsyncTask<Void, Void, Boolean>() {
Exception error;
#Override
protected Boolean doInBackground(Void... params) {
try {
// do work
return true;
} catch (Exception e) {
error = e;
return false;
}
}
#Override
protected void onPostExecute(Boolean result) {
if (result) {
Toast.makeText(ctx, "Success!",
Toast.LENGTH_SHORT).show();
} else {
if (error != null) {
Toast.makeText(getApplicationContext(), error.getMessage(),
Toast.LENGTH_SHORT).show();
//error occurs hide button here
}
}
}
}

How to load progress bar in android until response comes from server

Hi In my Application I'm sending one request to server to validate the user,after sending the request I'm storing that value in database and making the status as 1, after some time I'm changing the status to 2 in database.Now my android app should wait till the status becomes 2. For this I'm showing the user in mobile progress bar.But my problem is as soon as I send the request progress bar stops displaying in the mobile.
Here is what I have tried.
progressDialog = new ProgressDialog(MainActivity.this);
progressDialog.show();
progressDialog.setTitle("Please Wait");
progressDialog.setMax(100);
e1 = edittext.getText().toString();
//Toast.makeText(MainActivity.this, "" + e1, Toast.LENGTH_SHORT).show();
AsyncHttpClient client = new AsyncHttpClient();
final RequestParams params = new RequestParams();
params.put("sendingJSON", composeJSON());
client.post("http://192.168.43.137/gpstracker/check_user.php", params, new AsyncHttpResponseHandler() {
public void onSuccess(String response) {
Gson gson = new GsonBuilder().create();
try {
progressDialog.dismiss();
JSONArray arr = new JSONArray(response);
for (int i = 0; i < arr.length(); i++) {
JSONObject obj = (JSONObject) arr.get(i);
String general = obj.get("success").toString();
Toast.makeText(getApplicationContext(), ""+general, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void onFailure(int statusCode, Throwable error, String content) {
if (statusCode == 404) {
Toast.makeText(getApplicationContext(), "Requested resource not found", Toast.LENGTH_LONG).show();
} else if (statusCode == 500) {
Toast.makeText(getApplicationContext(), "Something went wrong at server end", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Unexpected Error occcured! [Most common Error: Device might not be connected to Internet]",Toast.LENGTH_LONG).show();
}
}
});
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton) {
// what ever you want to do with No option.
}
}
);
alert.show();
}
A good solution in this cases is to work with events. Using events you can notify everywhere that something is happening. In your case, you can send an event when "the status changes to 2 in the database" and dismiss the progress dialog. There is a powerful and easy-to-use library to work with events called eventbus:
https://github.com/greenrobot/EventBus
I hope this helps to clarify!
I would recomend you to use an AsynkTask to do it. You can create the progress dialog in the onPreExecute() method, do what you are trying to do (post action or database update) in doInBackground() and once you have everything you want, in the onPostExecute() you can dismiss the dialog and send the result/data, if you need to, to your activity.
public class yourAsyncTask extends AsynkTask<Params, Params, Params>
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage("Charging...");
pDialog.setCancelable(true);
pDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
#Override
public void onCancel(DialogInterface dialog) {
errorMesaje = "Process cancelled";
cancel(true);
}
});
pDialog.show();
}
#Override
protected Void doInBackground(Params... params) {
//Do your things here...
#Override
protected void onPostExecute(Void void) {
super.onPostExecute(void);
//Use an interface to call your activity and pass the data, you will have to change the attribute of the method in order to do it.
// Dismiss your dialog when your requests have finished
pDialog.dismiss();
}
I donĀ“t understand what are you trying to do exactly, if you just want to be sure that the post action is completed before the progress bar goes off, this solution will be fine. You can also call in the doInBackground() to your database and update it.
Hope it's clear enough!

Android Tweet message is not Showing on Twitter Wall

i know i have aske dthis question,but i am not getting any satisfaction solution till yet.,i registered in twitter for getting consumer key,and secret key.,i am getting login ,but when i update any message on twitter it show sme message has been updated,but when i am checkinh in my twitterid.,i am not getting any message.
public class MainActivity extends Activity {// Constants
static String TWITTER_CONSUMER_KEY = ""; // place your cosumer key here
static String TWITTER_CONSUMER_SECRET = ""; // place your consumer secret here
// Preference Constants
static String PREFERENCE_NAME = "twitter_oauth";
static final String oauth_token = "";
static final String oauth_token_secret = "";
static final String PREF_KEY_TWITTER_LOGIN = "";
static final String TWITTER_CALLBACK_URL = "";
// Twitter oauth urls
static final String URL_TWITTER_AUTH = "oauth_autherize";
static final String URL_TWITTER_OAUTH_VERIFIER = "oauth_verifier";
static final String URL_TWITTER_OAUTH_TOKEN = "oauth_token";
// Login button
private Button btnLoginTwitter;
// Update status button
private Button btnUpdateStatus;
// Logout button
private Button btnLogoutTwitter;
// EditText for update
private EditText txtUpdate;
// lbl update
private TextView lblUpdate;
private TextView lblUserName;
// Progress dialog
ProgressDialog pDialog;
// Twitter
private static Twitter twitter;
private static RequestToken requestToken;
private AccessToken accessToken;
// Shared Preferences
private static SharedPreferences mSharedPreferences;
// Internet Connection detector
private ConnectionDetector cd;
// Alert Dialog Manager
AlertDialogManager alert = new AlertDialogManager();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
cd = new ConnectionDetector(getApplicationContext());
// Check if Internet present
if (!cd.isConnectingToInternet()) {
// Internet Connection is not present
alert.showAlertDialog(MainActivity.this, "Internet Connection Error",
"Please connect to working Internet connection", false);
// stop executing code by return
return;
}
// Check if twitter keys are set
if(TWITTER_CONSUMER_KEY.trim().length() == 0 || TWITTER_CONSUMER_SECRET.trim().length() == 0){
// Internet Connection is not present
alert.showAlertDialog(MainActivity.this, "Twitter oAuth tokens", "Please set your twitter oauth tokens first!", false);
// stop executing code by return
return;
}
// All UI elements
btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter);
btnUpdateStatus = (Button) findViewById(R.id.btnUpdateStatus);
btnLogoutTwitter = (Button) findViewById(R.id.btnLogoutTwitter);
txtUpdate = (EditText) findViewById(R.id.txtUpdateStatus);
lblUpdate = (TextView) findViewById(R.id.lblUpdate);
lblUserName = (TextView) findViewById(R.id.lblUserName);
// Shared Preferences
mSharedPreferences = getApplicationContext().getSharedPreferences(
"MyPref", 0);
btnLoginTwitter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// Call login twitter function
loginToTwitter();
}
});
btnUpdateStatus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Call update status function
// Get the status from EditText
String status = txtUpdate.getText().toString();
new updateTwitterStatus().execute(status);
}
});
btnLogoutTwitter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// Call logout twitter function
logoutFromTwitter();
}
});
if (!isTwitterLoggedInAlready()) {
Uri uri = getIntent().getData();
if (uri != null && uri.toString().startsWith(TWITTER_CALLBACK_URL)) {
// oAuth verifier
final String verifier = uri
.getQueryParameter(URL_TWITTER_OAUTH_VERIFIER);
try {
Thread thread = new Thread(new Runnable(){
#Override
public void run() {
try {
// Get the access token
MainActivity.this.accessToken = twitter.getOAuthAccessToken(
requestToken, verifier);
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
// Shared Preferences
Editor e = mSharedPreferences.edit();
e.putString(oauth_token, accessToken.getToken());
e.putString(oauth_token_secret,
accessToken.getTokenSecret());
// Store login status - true
e.putBoolean(PREF_KEY_TWITTER_LOGIN, true);
e.commit(); // save changes
Log.e("Twitter OAuth Token", "> " + accessToken.getToken());
// Hide login button
btnLoginTwitter.setVisibility(View.GONE);
// Show Update Twitter
lblUpdate.setVisibility(View.VISIBLE);
txtUpdate.setVisibility(View.VISIBLE);
btnUpdateStatus.setVisibility(View.VISIBLE);
btnLogoutTwitter.setVisibility(View.VISIBLE);
// Getting user details from twitter
// For now i am getting his name only
long userID = accessToken.getUserId();
User user = twitter.showUser(userID);
String username = user.getName();
// Displaying in xml ui
lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>"));
} catch (Exception e) {
// Check log for login errors
Log.e("Twitter Login Error", "> " + e.getMessage());
e.printStackTrace();
}
}
}
}
private void loginToTwitter() {
// Check if already logged in
if (!isTwitterLoggedInAlready()) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
twitter4j.conf.Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
Thread thread = new Thread(new Runnable(){
#Override
public void run() {
try {
requestToken = twitter
.getOAuthRequestToken(TWITTER_CALLBACK_URL);
MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(requestToken.getAuthenticationURL())));
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
} else {
// user already logged into twitter
Toast.makeText(getApplicationContext(),
"Already Logged into twitter", Toast.LENGTH_LONG).show();
}
}
class updateTwitterStatus extends AsyncTask<String, String, String> {
private int statusId;
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Updating to twitter...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
protected String doInBackground(String... args) {
Log.d("Tweet Text", "> " + args[0]);
String status = args[0];
try {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
// Access Token
String access_token = mSharedPreferences.getString(oauth_token,"");
// Access Token Secret
String access_token_secret = mSharedPreferences.getString(oauth_token_secret, "");
AccessToken accessToken = new AccessToken(access_token, access_token_secret);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
// Update status
twitter4j.Status response = twitter.updateStatus(status);
Log.d("Status", "> " + response.getText());
} catch (TwitterException e) {
// Error in updating status
Log.d("Twitter Update Error", e.getMessage());
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
pDialog.dismiss();
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),
"Status tweeted successfully", Toast.LENGTH_SHORT)
.show();
txtUpdate.setText("");
}
});
}
}
private void logoutFromTwitter() {
// Clear the shared preferences
Editor e = mSharedPreferences.edit();
e.remove(oauth_token);
e.remove(oauth_token_secret);
e.remove(PREF_KEY_TWITTER_LOGIN);
e.commit();
btnLogoutTwitter.setVisibility(View.GONE);
btnUpdateStatus.setVisibility(View.GONE);
txtUpdate.setVisibility(View.GONE);
lblUpdate.setVisibility(View.GONE);
lblUserName.setText("");
lblUserName.setVisibility(View.GONE);
btnLoginTwitter.setVisibility(View.VISIBLE);
}
private boolean isTwitterLoggedInAlready() {
// return twitter login status from Shared Preferences
return mSharedPreferences.getBoolean(PREF_KEY_TWITTER_LOGIN, false);
}
protected void onResume() {
super.onResume();
}
}
here i am getting this image.,when i get logedin..
I think you forget to add the OAuth consumer keys and secrets into Assets in oauth_consumer.properties file, that you can get by registering your application with twitter. They have bundled keys so that you can test quickly, but it is strongly recommended that you change these keys. First, it is a security issue for your application and secondly sometimes our keys give errors because too many developers are testing.
SocialAuth Android is an Android version of popular SocialAuth Java library. Now you do not need to integrate multiple SDKs if you want to integrate your application with multiple social networks. You just need to add few lines of code after integrating the SocialAuth Android library in your app. Go to this socialauth-android. One of the best approach to integrate all social media.
Go to this link for better understanding socialauth-android .also, code available in Github

Android asynctask not displaying anything

I have a file that is supposed to pull a list of products from my MySQL database, encode them into a JSON array then I need to make the Android application display those.
Ideally I want it to display icons but that's something I can tinker with later for now I just want to get it to work
Using the current code below when I click the button it doesn't do anything. My LogCat shows my JSON perfectly fine but the app doesn't display anything, or crash.
public class GetProducts extends Activity {
//Delcare Variables
// JSON Response node names
private static String KEY_SUCCESS = "success";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.view_products);
Functions userFunctions = new Functions();
if(!userFunctions.isConnected(getApplicationContext()))
{
displayDialogue("Connection Error","Your network settings are invalid - please turn on network settings ", "Open Network Settings");
}
if(!userFunctions.isUserLoggedIn(getApplicationContext())){
Intent i = new Intent(GetProducts.this, FirstScreen.class);
startActivity(i);
}
Button btnLogin;
btnLogin = (Button)findViewById(R.id.btnGetProducts);
//When our login button is pressed
btnLogin.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
new LoginTask().execute();
}
});
//Assign the variables our layout buttons
}
//We are using an AsyncTask so that this function runs on a seperate thread of the processor
//Since 4.2 + Android requires any web or HTTP activity to be ran seperate thread to the GUI
class LoginTask extends AsyncTask<String, String, String> {
#Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
//Run the login function
Login();
return null;
}
}
public void displayDialogue(String title, String Message, String Button){
final AlertDialog.Builder myDialogue = new AlertDialog.Builder(this);
myDialogue.setTitle(title);
myDialogue.setMessage(Message);
TextView messageView = new TextView(this);
messageView.setGravity(Gravity.CENTER);
myDialogue.setView(messageView);
myDialogue.setCancelable(false);
myDialogue.setPositiveButton(Button, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = myDialogue.create();
dialog.show();
}
public void Login(){
try{
Functions userFunctions = new Functions();
final JSONObject json = userFunctions.getProducts();
JSONObject json_user = json.getJSONObject("products");
JSONArray jArray;
jArray = json.getJSONArray("products");
if (json.getString("success") != null) {
String res = json.getString("success");
if(Integer.parseInt(res) == 1){
try{
// user successfully logged in
// Store user details in SQLite Database
runOnUiThread(new Runnable() {
#Override
public void run() {
try {
displayDialogue("Error",json.getString("name"), "Try Again");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
// Clear all previous data in database
// Close Login Screen
finish();
}
catch(final Exception e){
runOnUiThread(new Runnable() {
#Override
public void run() {
displayDialogue("Error",e.toString(), "Try Again");
}
});
}
}
else{
runOnUiThread(new Runnable() {
#Override
public void run() {
displayDialogue("Error", "Error. \nWrong username / password combination please re-enter the details", "Try Again");
}
});
}
}else{
runOnUiThread(new Runnable() {
#Override
public void run() {
displayDialogue("Error", "Error. \nGeneric Error", "Try Again");
}
});
}
}
catch(JSONException e){
e.printStackTrace();
}
}
}
JSON result:- (Printed to Logcat)
12-27 16:53:45.011: E/JSON(23028): {"tag":"getProducts","success":1,"error":0,"products":{"name":"Coffee1","price":"4.00","image":"http:\/\/test.com"}}{"tag":"getProducts","success":1,"error":0,"products":{"name":"Coffee2","price":"5.00","image":"http:\/\/test2.com"}}
Any help would be great, thanks!

show tweets in a listview in twitter4j

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 code example given on the Twitter4j website:
public class MainActivity extends Activity {
//ListView with the tweets
private ListView timelineListView;
// Alert Dialog Manager
AlertDialogManager alert = new AlertDialogManager();
//Adapter
ArrayAdapter<twitter4j.Status> tweetAdapter ;
//List
List<Status> 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 <Void, Void, Void>{
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<twitter4j.Status>(MainActivity.this, android.R.layout.simple_list_item_1, rawStatuses);
timelineListView.setAdapter(tweetAdapter);
}
});
}
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:
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:
List <User, Tweet, ID, Time> ), but it seems to me cumbersome and a very poor solution.
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 this answer, but the link given doesn't work anymore.
I hope I have explained myself. Thanks in advance.
I was running into the same problem, and you're actually on the right path here. What I did to resolve this was also create a list of Strings and storing that into an ArrayList, then putting that list into and ArrayAdapter rather that the raw statuses:
ArrayAdapter<String> stringTweetAdapter;
List<twitter4j.Status> statuses;
List<String> stringStatuses = new ArrayList<String>();
.....
User user = twitter.verifyCredentials();
statuses = twitter.getHomeTimeline();
System.out.println("Showing #" + user.getScreenName() + "'s home timeline.");
for (twitter4j.Status status : statuses) {
Log.d("Twitter","#" + status.getUser().getScreenName() + " - " + status.getText());
String myTweets = ("#" + status.getUser().getScreenName() + " - " + status.getText());
stringStatuses.add(myTweets);
}
......
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
progressDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getApplicationContext(),"Retrieving TimeLine Done..", Toast.LENGTH_SHORT).show();
stringTweetAdapter = new ArrayAdapter<String>(ShowTimeline.this, R.layout.timeline_list_item, R.id.textTimelineItem, stringStatuses);
twitterFeed.setAdapter(stringTweetAdapter);
}
});
}

Categories

Resources