setItemOnClickListener error after click

1

I'm having a problem in the application where after I click on some line of my ListView , the application simply crashes (not being able to see the error in the Debugger).

The idea is to click on the ListView line data to go to EditText on my other Activity .

Follow the code below:

    public class FillList extends AsyncTask <String,String,String> {
    String z="";
    List<Map<String, String>> prolist = new ArrayList<Map<String, String>>();
    @Override public void onPreExecute()
    {
        progbar2.setVisibility(View.VISIBLE);
    }

    @Override public  void onPostExecute(String r){
        progbar2.setVisibility(View.GONE);
        //Toast.makeText(MegaPermanentes_Usuarios.this, r, Toast.LENGTH_SHORT).show();

        String[] from = {"A", "B"};
        int[] views = {R.id.lblproname, R.id.lblproend};
        final SimpleAdapter ADA = new SimpleAdapter(MegaPermanentes_Usuarios.this, prolist, R.layout.lsttemplate, from, views);
        listPro.setAdapter(ADA);

        listPro.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //Bundle params = new Bundle();
                String resposta = (String) parent.getAdapter().getItem(position);
                Intent it = new Intent(MegaPermanentes_Usuarios.this, MegaPermanentes.class);
                it.putExtra("nome",resposta);
                startActivity(it);

            }
        });


    }

    @Override
    public String doInBackground(String... params) {

        try{
            Connection con = connectionClass.connectionclass();
            if(con == null){
                z = "Conexão falhou";
            }else
                {
                String query = "select nome,endereco from usuarios";
                PreparedStatement ps = con.prepareStatement(query);
                ResultSet rs = ps.executeQuery();

                while(rs.next()){
                    Map<String, String> datanum = new HashMap<String, String>();
                    datanum.put("A", rs.getString ("Nome"));
                    datanum.put("B", rs.getString("Endereco"));
                    prolist.add(datanum);
                }


            }


        }catch (Exception ex)
        {
            z = "Error Retrieving Data";
        }
        return z;
    }


}

Here is the part of onItemClickListener :

 listPro.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //Bundle params = new Bundle();
                String resposta = (String) parent.getAdapter().getItem(position);
                Intent it = new Intent(MegaPermanentes_Usuarios.this, MegaPermanentes.class);
                it.putExtra("nome",resposta);
                startActivity(it);

            }
        });
    
asked by anonymous 31.08.2017 / 15:14

1 answer

0

As you can see, you create an object using Map and insert into each item of your ListView . Therefore, to retrieve the data, you must also use Map . Here is an example:

// recuperando o valor do item após o click
Map<String, String> obj = (Map<String, String>) getAdapter().getItem(position);
// recuperando o nome
String name = (String) obj.get("A");
// recuperando o endereço
String address = (String) obj.get("B");
    
01.09.2017 / 02:27