How to share the contents of a listiview?

0

Hello, I have a question. I am making an APP, in which it has a listview that has texts and an image. I'd like to know how I can share the content that the person clicked on.

Here is my code:

// DECLARANDO COMPONENTES

    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,
    };


    String[] ac_Contra_ComoVotou={
            "SIM"
    };


@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)
            {


Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);


            }
        });

THANK YOU VERY MUCH !!!

    
asked by anonymous 14.09.2017 / 16:58

1 answer

2

You just capitalize the position relative to the String vector within setOnItemClickListener . Here is an example:

String text = ac_Contra[position];  

How to stay in onItemClick :

list.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        String text = ac_Contra[position];

        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        // aqui você define o texto para compartilhamento.
        sendIntent.putExtra(Intent.EXTRA_TEXT, text);
        sendIntent.setType("text/plain");
        startActivity(sendIntent);

    }
});

Following this same logic, you define other values for the text variable that you want to share through Intent.ACTION_SEND .

    
14.09.2017 / 19:11