0

我使用 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运行良好),我认为问题出在线程中,但我不完全知道在哪里

4

0 回答 0