问题
I am fetching data from server and set it into listview. Each Listview item have Two textview and a button. I have implemented all the code and working perfect.. But can any one help me.. How to implement facebook share intent when click on button of particular listview item.I want to share offer_name to facebook wall post using share intent chooser.

Here is my getView code :-
public View getView(int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.offer_list_item, parent,
false);
holder.tv1 = (TextView) convertView.findViewById(R.id.offer_name);
holder.tv2 = (TextView) convertView.findViewById(R.id.expiry_date);
holder.b = (Button) convertView.findViewById(R.id.item_button);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Item1 it = item.get(position);
holder.tv1.setText(it.getoffer_name());
holder.tv2.setText("offer ends:" + it.getexpiry_date());
holder.b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// holder.b.setText("Joined");
// holder.b.setTextColor(Color.parseColor("#ffffff"));
// holder.b.setTextSize(10);
}
});
return convertView;
}
回答1:
First of all you can only share a link on a Facebook wall. You can't send any pre-filled messages - it is against Facebook policy.
Second of all you should stick to the guidelines and not force the user to use a specific share-channel (reference)
You could filter the Apps that respond to share Intent
(e. g. link) but please have in mind that not all users can have Facebook installed.
All in all I don't think that this is a good idea.
回答2:
lv.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
for (int i = 0; i <= 100; i++) {
if (position == i) {
lv.setDrawingCacheEnabled(true);
Bitmap bitmap = lv.getDrawingCache();
File cache = getApplicationContext().getExternalCacheDir();
File sharefile = new File(cache, "toshare.png");
try {
FileOutputStream out = new FileOutputStream(sharefile);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (IOException e) {
}
Intent share = new Intent(android.content.Intent.ACTION_SEND);
share.setType("image/*");
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + sharefile));
startActivity(share);
startActivity(Intent.createChooser(share, "Send your picture using:"));
}
}
}
});
来源:https://stackoverflow.com/questions/22634154/share-listview-item-on-facebook-wallpost-using-share-intent-chooser