1
I am having a problem in the application where after I click some row of mine ListView
, the application simply crashes (unable to see the error in Debugger).
The idea is after clicking on ListView
the line data go to the EditText
in 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’s 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);
}
});
try to recover the String answer = ADA.getItem(position)
– André Ozawa
Would look like this?
String resposta = (String) ADA.getItem(position);
? And yet you’re crashing.– Matheus Arduino
The class Megapermanent is registered on Androidmanifest.xml?
– Leonardo Dias
@Leonardodias, yes:
</activity>
 <activity android:name=".MegaPermanentes" />
 <activity android:name=".MegaPermanentes_Usuarios"></activity>
– Matheus Arduino
Try to do it that way then: String response = (String) (listPro.getItemAtPosition(position));
– Leonardo Dias
Yes, actually it would be String answer = (String) ADA.getItem(position). get("A"); Because getItem is returning you a Hashmap
– André Ozawa
@Andreozawa would be
.get("A")
same? In AS did not recognize this syntax.– Matheus Arduino
@Leonardodias without advance also, continues crashing at the same time that I click on
ListView
.– Matheus Arduino