Good morning. I have this query because I am too new programming in Android Studio and I do not know where to go. I have a listView that I load with data from a database that I have on my PC and I obtain the data by a php file. That's ok, the list shows it to me. What I need is to be able to click on an iten in the listView and take me to another activity where I can capture the ID of the record to which I'm clicking. The list is added as follows:
public ArrayList<String> obtDatosJSON(String response){
ArrayList<String> listado = new ArrayList<String>();
try{
JSONArray jsonArray = new JSONArray(response);
String texto;
for (int i = 0; i < jsonArray.length();i++){
texto = "\n" +
"Barrio: " + jsonArray.getJSONObject(i).getString("barrio") +"\n"+
"Dirección: " + jsonArray.getJSONObject(i).getString("direccion") +" "+
"Piso Depto: " + jsonArray.getJSONObject(i).getString("pisoDepto") +" "+
"Cliente: " + jsonArray.getJSONObject(i).getString("cliente") +"\n"+
"Telefono: " + jsonArray.getJSONObject(i).getString("telefono") + "\n" +
"Estado: " + jsonArray.getJSONObject(i).getString("estado") + "\n" +
"Cadete Asignado: " + jsonArray.getJSONObject(i).getString("cadete") + "\n";
listado.add(texto);
}
}catch(Exception e){
e.printStackTrace();
}
return listado;
}
Then I made that when I clicked on an item it took me to another Activity:
public void CargarLista(ArrayList<String> datos){
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,datos);
listado.setAdapter(adapter);
listado.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
Intent intent = new Intent(view.getContext(),Detalle.class);
intent.putExtra("ID","");
startActivity(intent);
}
});
}
What I do not know is how to pass the ID of the record, there I saw that it goes in the intent.putExtra. Here's where I do not know what to do: Is it okay to create a variable with the JSON data?
String Idetalle = jsonArray.getJSONObject(i).getString("id");
But dsp that variable does not let me call it or I do not know how to do it inside the intent.putExtra.
Do they guide me more or less how to achieve what I need?
It would even be useful if they see it and they tell me that everything is wrong from the beginning so I would look for another way to do it.