open a new activity when clicking on an item in the listview

0

I created a listview but I'm not sure what command I should do for my items to open a new activity for each one.

Below is my code so far:

public class pg_apoio extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pg_apoio);

        ListView listadeapoio = (ListView) findViewById(R.id.listadoapoio);
        ArrayAdapter adapter = new listaapoioadapter(this, adicionarguias());
        listadeapoio.setAdapter(adapter);

        listadeapoio.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(pg_apoio.this, pg_bjcp.class);
                startActivity(intent);
            }
        });

    }



    private ArrayList<listaapoio> adicionarguias() {
        ArrayList<listaapoio> listaapoios = new ArrayList<listaapoio>();

        listaapoio e = new listaapoio ("Guia BJCP 2015", "guia em portugûes",R.drawable.pdf_icon);

        listaapoios.add(e);
        e= new listaapoio("Lupulo", "Guia de lupulos", R.drawable.hop1);

        listaapoios.add(e);
        e= new listaapoio("Levedura", "Guia de leveduras", R.drawable.yeast_icon);

        listaapoios.add(e);
        e= new listaapoio("Harmonização", "Guia de harmonização com cerveja", R.drawable.harmo_icon);

        listaapoios.add(e);
        e= new listaapoio("Taças", "Guia de taças para cada estilo", R.drawable.beerglass_icon);

        listaapoios.add(e);
        e= new listaapoio("Receitas", "Receitas prontas", R.drawable.receita_icon);

        listaapoios.add(e);
        e= new listaapoio("Links" ,"Canais de cervejeiros artesanais", R.drawable.youtubelogo_icon);

        listaapoios.add(e);
        e= new listaapoio("teste", "teste da lista", R.drawable.pdf_icon);

        return listaapoios;

    }

}
    
asked by anonymous 01.08.2018 / 02:58

1 answer

0

In the method, public void onItemClick (AdapterView adapterView, View view, int i, long l), it returns you the data of the list item that you clicked. Example that my code piece of code

       listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            OrdemServico ordemServico = (OrdemServico) parent.getAdapter().getItem(position)

I'm retrieving the object that is related to the item from the listview, so I'm just removing some attribute from it. Ex: if (service-order.getId = x) {go here} Ex: if (service-order.getId = y) {go there}

How is that list going to return, and

    
03.08.2018 / 18:10