Question

Dans mon application, lorsqu'il n'y a pas de connexion WiFi, j'allume la connexion WiFi avec un alertdialog et j'appelle l'écran des paramètres WiFi. Lorsque j'appuie sur le bouton arrière, je suppose qu'il va dans la méthode onResume () de la mainactivité. Dans cette méthode, j'appelle une méthode LoadTweets, qui recharge mes tweets. Cela fonctionne lorsque je passe d'une activité à une autre.

Lorsque je reviens dans l'écran des paramètres WiFi, le débogueur va dans la méthode OnResume, parcoure la méthode LoadTweets, mais elle ne montre pas les tweets rechargés.

Est-ce que je manque une étape ici?

Méthode onResume ():

public void onResume(){
    super.onResume();
    checkWifi();   
    loadTweets();
}

Méthode LoadTweets:

private ArrayList<Tweets> loadTweets(){
ArrayList<Tweets> tweets = new ArrayList<Tweets>();
try {
        HttpClient hc = new DefaultHttpClient();
        HttpGet get = new
        HttpGet("http://search.twitter.com/search.json?q=JobXXL_be&rpp=5");
        HttpResponse rp = hc.execute(get);
        if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
        {
                String result = EntityUtils.toString(rp.getEntity());
                JSONObject root = new JSONObject(result);
                JSONArray sessions = root.getJSONArray("results");
                for (int i = 0; i < sessions.length(); i++) {
                        JSONObject session = sessions.getJSONObject(i);
                        Tweets tweet = new Tweets();
                        tweet.setTweet(session.getString("text"));
                        tweet.setUser(session.getString("from_user"));
                        tweet.setDate(session.getString("created_at").substring(5,16));
                        tweets.add(tweet);
                }
        }
} catch (Exception e) {
        Log.e("TwitterFeedActivity", "Error loading JSON", e);
 }
 return tweets;
}

Classe TweetListAdapter:

private class TweetListAdaptor extends ArrayAdapter<Tweets> {
                private ArrayList<Tweets> tweets;
                public TweetListAdaptor(Context context, int textViewResourceId, ArrayList<Tweets> tweets) {
                         super(context, textViewResourceId, tweets);
                         this.tweets = loadTweets();
                }
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                        View v = convertView;
                        if (v == null) {
                                LayoutInflater vi = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE);
                                v = vi.inflate(R.layout.tweetitem, null);
                        }
                        Tweets o = tweets.get(position);
                        TextView tt = (TextView) v.findViewById(R.id.TWEET_TEXT);
                        TextView bt = (TextView) v.findViewById(R.id.TWEET_SCREEN_NAME);
                        TextView date = (TextView) v.findViewById(R.id.TWEET_CREATED_AT);
                        tt.setText(o.getTweet());
                        bt.setText(o.getUser());
                        date.setText(o.getDate());
                        return v;
                }

                public void setTweets(ArrayList<Tweets> tweet){
                    this.tweets = tweet;
                }
            }

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top