I am working on a project with sound arduino the theme that every few minutes a new datum is added to the bd, but I want to show in an android view the last data entered and update when a new datum is added the issue is that I have raised a half idea but I do not find it shows me nothing.
(the code is a fragment that returns all the data in a RecyclerView that works)
public void Datosonido() {
String Url = "http://localhost:82/list.php";
AsyncHttpClient client = new AsyncHttpClient();
client.post(Url, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
if (statusCode == 200) {
String resp = new String(responseBody);
cargar(resp);
Log.e("INFO", resp);
}
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
}
});
}
public void cargar(String respuesta){
LinearLayoutManager lm = new LinearLayoutManager(getActivity());
lm.setOrientation(LinearLayoutManager.VERTICAL);
rc.setLayoutManager(lm);
try {
List<Sonido> lista=new ArrayList<>();
JSONArray json = new JSONArray(respuesta);
for (int i = 0; i < json.length(); i++) {
Sonido s = new Sonido();
s.id = json.getJSONObject(i).getInt("id");
s.nombre = json.getJSONObject(i).getString("name");
s.valor = json.getJSONObject(i).getDouble("valor1");
s.fecha = json.getJSONObject(i).getString("fecha");
lista.add(s);
Log.e("AAAAAAAAAAAAA",s.nombre);
}
Adaptador a = new Adaptador(lista,this,R.layout.item_sound);
rc.setAdapter(a);
}catch (Exception e){
e.printStackTrace();
}
}
Current Registrations
[{"id":"1","name":"A","valor1":"1","fecha":"2018-12-11"},{"id":"2","name":"Sonido","valor1":"709","fecha":"2018-12-11"},{"id":"3","name":"Sonido","valor1":"710","fecha":"2018-12-11"}]
with this you should show me the last record with all your data in a fragment A contribution with an idea to solve this problem would be very helpful. try in the json for part to do a for instead of i ++ to put json.lenght () - 1 and i-- but it did not work for me