我在我的应用程序中使用android facebook sdk,特别是ShareDialog(点击按钮后)。它工作得很好,唯一的问题是Post对话框显示为空,没有我在代码中设置的内容。请注意,我正在使用ListFragment,这就是为什么我的类扩展了ArrayAdapter并且我不在活动中。这是我的代码:
public class CustomAdapter extends ArrayAdapter<ModelVoted> {
String [] result;
private final Activity context;
private final List<ModelVoted> stateList;
ShareDialog shareDialog;
public CustomAdapter(Activity context, List<ModelVoted> listS, String[] list) {
super(context, R.layout.list_item, listS);
result=list;
this.context = context;
this.stateList = listS;
}
@Override
public int getCount(){
return result.length;
}
@Override
public long getItemId(int position){
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Holder holder = null; //final Holder holder=new Holder();
if(convertView==null) {
LayoutInflater inflater = context.getLayoutInflater();
convertView = inflater.inflate(R.layout.list_item, null, false);
holder=new Holder();
holder.shareButton= (ImageButton)convertView.findViewById(R.id.imageButton);
holder.shareButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
shareDialog = new ShareDialog(context);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hi! I just used the app! ")
.setContentDescription(
"Hi! This is my post: " + result[position])
.build();
shareDialog.show(linkContent);
}
}
});
}else{
holder = (Holder) convertView.getTag();
}
return convertView;
}
答案 0 :(得分:1)
我在Facebook最新的sdk遇到同样的问题,我已经决定使用如下的设置ContentUri。
ShareDialog shareDialog = new ShareDialog(baseActivity);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hi! I just used the app! ")
.setContentDescription(
"Hi! This is my post: " + result[position])
.setContentUrl(Uri.parse("http://www.*****.com/"))
.build();
shareDialog.show(linkContent);
}