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