我制作了一个应用程序,其中我正在获取我所有Facebook 朋友生日的列表,如下所示:
瑞奇
1990 年 2 月 13 日
但现在我想展示这样的东西:
瑞奇
1990 年 2 月 13 日
代码:-
我的适配器.java
TextView name = (TextView) v.findViewById(R.id.label);
name.setText(friend.getName());
TextView bday = (TextView) v.findViewById(R.id.label2);
if (!friend.getBday().trim().equals("")) {
bday.setText(friend.getBday());
} else {
bday.setText("Not Mentioned");
}
return v;
}
我的Facebook.java
public void init(Main main) {
this.main = main;
mFacebook = new Facebook(APP_ID);
isReady = false;
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
mFacebook.authorize(main, new String[] { "publish_stream",
"friends_birthday" }, new MyAuthorizeListener());
}
// ref- http://developers.facebook.com/docs/reference/api/user/
public Report reLoadAllFriends() {
if (!isReady) {
Log.v(TAG, "myfacebook.reloadallfriends Not ready yet!");
return new Report(false, "Not ready yet!");
}
Bundle params = new Bundle();
params.putString("fields", "id,name,birthday,picture");
mAsyncRunner.request("me/friends", params, new MyRequestListener(
RequestType.FRIEND_LIST));
Log.v(TAG, "myfacebook.reloadallfriends Fetch started.");
return new Report(true, "Fetch started");
}
public List<MyFriend> getAllFriends() {
return getFilteredFriends(null);
}
public List<MyFriend> getFilteredFriends(com.january.floogoo.Filter week) {
return Main.db.getFriendsFilteredBy(week);
}
public List<Map<String, String>> getAllFriendsAsMap() {
return getFilteredFriendsAsMap(null);
}
public List<Map<String, String>> getFilteredFriendsAsMap(Filter filterBy) {
List<MyFriend> friendList = Main.db.getFriendsFilteredBy(filterBy);
List<Map<String, String>> list = new ArrayList<Map<String, String>>();
for (MyFriend friend : friendList) {
list.add(friend.getMap());
}
return list;
}
public void post(String receiver, String message) {
if (isReady) {
Bundle params = new Bundle();
params.putString("message", message);
mAsyncRunner.request(receiver + "/feed", params, "POST",
new MyRequestListener(RequestType.FEED_POST));
}
}
class MyAuthorizeListener extends BaseDialogListener {
public void onComplete(Bundle values) {
Log.i(TAG, "Authorization successfull");
isReady = true;
main.loadContents();
}
}
class MyRequestListener extends BaseRequestListener {
private RequestType type;
public MyRequestListener(RequestType type) {
this.type = type;
}
public void onComplete(final String response) {
try {
switch (type) {
case FRIEND_LIST:
Log.d(TAG, "myfacebook.friendlist Response: "
+ response.toString());
myFriends.clear();
JSONArray jarr = Util.parseJson(response).getJSONArray(
"data");
for (int i = 0; i < jarr.length(); i++) {
JSONObject json = jarr.getJSONObject(i);
String fbID = json.getString("id");
String name = json.getString("name");
String bday = json.optString("birthday");
String pic = json.getString("picture");
myFriends.add(new MyFriend(fbID, name, bday, pic));
}
main.notifyMain(Note.FRIENDLIST_RELOADED);
break;
case FEED_POST:
Log.d(TAG, "myfacebook.feedpost Response: "
+ response.toString());
break;
default:
break;
}
} catch (JSONException e) {
Log.e(TAG, "JSONException: " + e.getMessage());
} catch (FacebookError e) {
Log.e(TAG, "FacebookError: " + e.getMessage());
}
}
}
我的朋友.java
public class MyFriend {
private String fbID = " ";
private String name = " ";
private String bday = " "; // can be missing, be in form of mm/dd or
// mm/dd/yyyy
private String pic = " ";
private String bdayMessage = " ";
private boolean isAutoPost = false;
public MyFriend() {
}