在ListView中显示搜索Twitter4j的结果

时间:2013-08-01 11:30:09

标签: java android android-listview twitter4j

我使用Twitter4j获取带有主题标签的推文,我成功地在控制台中显示结果,但不在列表视图中显示

         list = new ArrayList<String>();
    arrayAdapter =  new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);
            listtwitt.setAdapter(arrayAdapter); 
            TwitAsyncTask twitAsync = new TwitAsyncTask();
            twitAsync.execute();


}

@SuppressLint("NewApi")
private class TwitAsyncTask extends AsyncTask<Void, Void, Void>{

    private ProgressDialog progressDialo;

    @Override
    protected void onPreExecute() {
         progressDialo = ProgressDialog.show(SocialNetwork.this, "", "En cours...");
        super.onPreExecute();

    }

    @Override
    protected Void doInBackground(Void... params) {
         final Query query = new Query();
            query.setQuery("%23morocco");
         QueryResult result;
        try {
            result = twitter.search(query);
             for (twitter4j.Status status : result.getTweets()) {
                        k++;
                        String stat = "@" + status.getUser().getScreenName() + ":" + status.getText() +":"+status.getGeoLocation() +":"+status.getCreatedAt();
                        SocialNetwork.list.add(stat);
                         System.out.println(stat);

                 }
        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

                    return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        progressDialo.dismiss();
        arrayAdapter.clear();
        arrayAdapter.addAll(SocialNetwork.list);
        arrayAdapter.notifyDataSetChanged();
        super.onPostExecute(result);
    }

}

我静态测试了一个随机字符串数组并显示了listview(listview效果很好),我认为问题出在线程中,但我不知道在哪里

0 个答案:

没有答案