I'm trying to integrate facebook "like" button into my Android app. I'm using Facebook SDK 4.1.2.
My app has the Main Activity with Navigation Drawer, which switches the Fragments. One of the Fragments has the ListView. I need facebook "like" button in every list item. I'm using custom BaseAdapter to construct the list items.
I don't have problems with the facebook signing in and with getting posts from some facebook page.
But I faced with the next problems:
- The "Like" button doesn't have any likes count, it just looks like this
By the way, is it possible to make this button looks like this?
- My "like" actions doesn't make any effect. I press the "like" button, some screen appears and fastly closes, and then I can't see any changes with the button, and the Facebook object (some page post) doesn't get my like (I check it via browser).
What am I missing with this task?
Here's parts of my code:
MainActivity.java
private CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
OpenFacebookSession();
mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();
// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
ListAdapter.java
public class ListAdapter extends BaseAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.feed_item, null);
LikeView likeView = (LikeView) convertView.findViewById(R.id.like_view);
likeView.setLikeViewStyle(LikeView.Style.BOX_COUNT);
likeView.setAuxiliaryViewPosition(LikeView.
AuxiliaryViewPosition.INLINE);
likeView.setObjectIdAndType(someID,//some Facebook object ID
activity-launchmode/en",
LikeView.ObjectType.OPEN_GRAPH);
return convertView;
}
}
feed_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/feed_bg"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="@dimen/feed_item_margin"
android:layout_marginRight="@dimen/feed_item_margin"
android:layout_marginTop="@dimen/feed_item_margin"
android:background="@drawable/bg_parent_rounded_corner"
android:orientation="vertical"
android:paddingBottom="@dimen/feed_item_padding_top_bottom"
android:paddingTop="@dimen/feed_item_padding_top_bottom" >
<com.facebook.share.widget.LikeView
android:id="@+id/like_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/feedImage1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</LinearLayout>
Aucun commentaire:
Enregistrer un commentaire