I have the following problem. I'm taking the sms from my message box, when I walk with the do while it brings me everything when I show it in the print, but when wanting to build the listview it only shows me the first message and the others ignore it. What will I be doing wrong? (I look at many publications but apparently everything is fine). On the other hand it does not throw errors, it only brings one and the others do not take them into account.
private void leerHistorial(){
Cursor cur = getContentResolver().query(Uri.parse(INBOX),null,null,null,null);
String numeroEmisorGPS = getString(R.string.numeroemisorGPS);
numeroEmisorGPS = numeroEmisorGPS.substring(numeroEmisorGPS.length()-8);
//TextView txtmensaje;
Button btnFollow;
myDialog.setContentView(R.layout.sms_popup);
// txtmensaje = (TextView) myDialog.findViewById(R.id.txtmensaje);
ListView lv1 = (ListView)myDialog.findViewById(R.id.listItems);
ArrayList<String> items = new ArrayList<>();
assert cur != null;
if (cur.moveToFirst()) { /* false = no sms */
do {
String emisor = cur.getString(cur.getColumnIndexOrThrow("address")).trim(); //TOMA EL NUMERO EMISOR DEL MENSAJE
String mensaje = cur.getString(cur.getColumnIndexOrThrow("body"));
if (emisor.length() >= 8){
emisor = emisor.substring(emisor.length()-8);
}
if (emisor.equals(numeroEmisorGPS) ) { //consulto si el numero emisor es el del GPS
items.add( mensaje);
System.out.println("numeros emisor --> " + emisor );
System.out.println("numeros emisor --> " + mensaje );
}
} while (cur.moveToNext());
}
ListAdapter adaptador = new ArrayAdapter<>(MainActivity.this,android.R.layout.simple_list_item_1,items);
lv1.setAdapter(adaptador);
btnFollow = (Button) myDialog.findViewById(R.id.btnfollow);
btnFollow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myDialog.dismiss();
}
});
myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
myDialog.show();
}
SMS_POPUP.XML
<?xml version="1.0" encoding="utf-8"?>
<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:src="@drawable/cuatrosmsentrada_icon"
android:contentDescription="@string/todo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F8F9F9"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nuevo_mensaje"
android:layout_gravity="center_horizontal"
android:textSize="18sp"
android:textColor="@color/colorPrimaryDark"
android:textAllCaps="true"/>
<ListView
android:id="@+id/listItems"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
<TextView
android:id="@+id/txtmensaje"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="20dp"
android:textColor="@color/colorPrimary"
android:textSize="18sp" />
</LinearLayout>