使用twitter 4j库,我抓住用户的最新推文,然后获取转推ID和他们的粉丝数。
现在我需要做的是显示转发者的ID,按照跟随者的降序排序,即最高的跟随者第一等级。
我抓住并将追随者数量计入树图,现在如何对它们进行排序?然后在TextView中显示它们?
使用twitter4j,我抓住用户的推文并将其置于“状态”状态。其余部分是: -
//get the first status
status = statuses.get(0);
//get id of the status
long l= status.getId();
//get retweeters id
ki =twitter.getRetweeterIds(l, 100, -1);
long[] id=ki.getIDs();
//for every retweeter id, get followers count and put in treemap
TreeMap<Integer,Long> tm = new TreeMap<Integer, Long>();
for(int k=0;k<=id.length;k++)
{
u = twitter.showUser(id[k]);
follower=u.getFollowersCount();
tm.put(follower,id[k] );
}
NavigableMap<Integer,Long> reverseTreeMap = tm.descendingMap();
答案 0 :(得分:0)
解决! 这就是我做的方式
//Using treemap to sort retweeters according to their followers
TreeMap<Integer,String> tm = new TreeMap<Integer, String>();
try{
for(int k=0;k<10;k++)
{
publishProgress(5);
Log.i(a, "treemap followers"+k);
u = twitter.showUser(id[k]);
follower=u.getFollowersCount();
url=u.getProfileImageURL();
tm.put(follower,url );
}
}
catch(Exception e)
{
Log.e(a, e.toString());
}
Log.i(a, "Done treemap");
//Reverse the order of the treemap
Log.i(a, "Reversing Treemap");
NavigableMap<Integer,String> reverseTreeMap = tm.descendingMap();
publishProgress(5);
//Put treemap values in string array
s=reverseTreeMap.values().toString();
s=s.replace("[", "");
s=s.replace("]", "");
Log.i(a, "Done");
//使用String数组在Textview或任何地方显示它们