如何从CursorAdapter打开Facebook Share Dialog?

时间:2017-05-10 13:47:00

标签: android facebook facebook-graph-api facebook-share

目前我正在开发一个简单的应用程序,其中包含带文本和文本的ListView。我想打开共享对话框,用户可以在Facebook墙上共享文本。

我使用CursorAdapter来填充数据&单击此按钮后会出现ImageButton,用户将能够直接共享文本消息。

我尝试在单独的Activity& amp;中使用Share Dialog。现在我想在这个适配器代码中包含。 那么,如何从Cursor Adapter代码打开ShareDialog,因为它需要Activity引用?任何一个例子将不胜感激。

这是我的CursorAdapter代码:

    public class MessageAdapterForListView extends CursorAdapter {

    private static final String TAG = MessageAdapterForListView.class.getSimpleName();
    Context mContext;
    Cursor mCursor;

    private CallbackManager callbackManager;
    private TextView textView;

    private AccessTokenTracker accessTokenTracker;
    private ProfileTracker profileTracker;

    public MessageAdapterForListView(Context context, Cursor c) {
        super(context, c);
        mContext = context;
        mCursor = c;
    }


    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());

        View retView = inflater.inflate(R.layout.list_item_message, parent, false);

        return retView;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        final ViewHolder holder = new ViewHolder();

        holder.messageText = (TextView) view.findViewById(R.id.message_text);
        holder.messageTitle = (TextView) view.findViewById(R.id.msg_title);
        holder.shareOnFb = (ImageButton) view.findViewById(R.id.share_on_fb);
        holder.shareOnFb.setFocusable(false);


        final String message = cursor.getString(cursor.getColumnIndex(DatabaseManager.MESSAGE_TEXT));
        String msgTitle = cursor.getString(cursor.getColumnIndex(DatabaseManager.MESSAGE_TITLE));
        String msgSerialId  = cursor.getString(cursor.getColumnIndex(DatabaseManager.MESSAGE_SERIAL_ID));




        holder.messageText.setText(message);
        holder.messageTitle.setText(msgTitle);

        ShareMessageOnFbHandler shareMessageOnFbHandler = new ShareMessageOnFbHandler(msgSerialId,msgTitle,message);
        holder.shareOnFb.setOnClickListener(shareMessageOnFbHandler);

        view.setTag(holder);
    }

    class ShareMessageOnFbHandler implements View.OnClickListener {

        private String mid , mtitle,mtext;
        public ShareMessageOnFbHandler(String msgSerialId , String msgTitle , String msgText)
        {
            this.mid = msgSerialId;
            this.mtitle = msgTitle;
            this.mtext = msgText;

        }

        public void onClick(View view) {


            Log.d(TAG,"Share Message For : "+this.mid +" Msg Title : "+this.mtitle +" Message : "+this.mtext);

        //From here I want to share text message on Facebook
        // Also ShareDialog requires Activity in constructor so , how do I get activity instance in adapter class

       }

    }

    static class ViewHolder {

        TextView messageTitle,messageText;
        ImageButton shareOnFb;

    }
}



  [1]: https://developers.facebook.com/docs/sharing/android

0 个答案:

没有答案