How do I click items in a list in Android Studio?

0

For the time being my code is like this? how to implement the click of the list items the click would be to open a new screen

    ListView lista_teste = (ListView)findViewById(R.id.lista_teste);
    String[] dados = new String[]{"xxxxx","xxxx"};
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, dados){
        @Override
        public View getView(int position, View convertView, ViewGroup parent){
            // Get the Item from ListView
            View view = super.getView(position, convertView, parent);

            // Initialize a TextView for ListView each Item
            TextView tv = (TextView) view.findViewById(android.R.id.text1);

            // Set the text color of TextView (ListView Item)
            tv.setTextColor(Color.WHITE);

            // Generate ListView Item using TextView
            return view;
        }
    };
    lista_teste.setAdapter(adapter);
    
asked by anonymous 06.10.2017 / 17:14

1 answer

1

John, for this you have to add the setOnItemClickListener event, see an example of the click event and opening a new screen:

lista_teste.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent mIntent = new Intent(context, SegundaTela.class);                
                // chama a nova tela
                startActivity(mIntent);
                // destrói a tela atual
                finish();

            }
        });
    
06.10.2017 / 17:51