我有一个问题。我正在制作一个APP,其中有一个listview
,它有文字和图像。我想知道如何分享用户点击的内容。
这是我的代码:
private ListView list;
// ARRAY CONTRA-AC
String[] ac_Contra = {
"Flaviano Melo",
"Jéssica Sales"
};
Integer[] ac_Contra_Imgid = {
R.drawable.flaviano_melo,
R.drawable.jessica_sales,
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// VINCULANDO COMPONENTES
list = (ListView) findViewById(R.id.list);
// CAPTURANDO INFORMAÇÕES DE OUTRA ACTIVITY
Bundle extra = getIntent().getExtras();
// Condição para execução do comando
if (extra != null)
{
String textoTransferido1 = extra.getString("CONTRA");
String textoTransferido2 = extra.getString("FAVOR");
String textoTransferido3 = extra.getString("INVESTIGADOS");
// CONDIÇÃO - ESTADO AC
if ("CONTRA-AC".equals(textoTransferido1))
{
CustomListAdapter adapter=new CustomListAdapter(this, ac_Contra, ac_Contra_Imgid, ac_Contra_partido,ac_Contra_ComoVotou);
list = (ListView)findViewById(R.id.list);
list.setAdapter(adapter);
}
// EVENTO DE CLIQUE
list.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
}
});
}
}
答案 0 :(得分:2)
您必须创建自定义适配器并添加要发送的按钮,并在该按钮上添加onClisckListener
,以便通过whatsapp进行共享
Uri imageUri = Uri.parse(pictureFile.getAbsolutePath());
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
//Target whatsapp:
shareIntent.setPackage("com.whatsapp");
//Add text and then Image URI
shareIntent.putExtra(Intent.EXTRA_TEXT, picture_text);
shareIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
shareIntent.setType("image/jpeg");
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
try {
startActivity(shareIntent);
} catch (android.content.ActivityNotFoundException ex) {
ToastHelper.MakeShortText("Whatsapp have not been installed.");
}