tengo el siguiente problema. Estoy tomando los sms de mi casilla de mensajes, al recorrer con el do while me trae todo cuando lo muestro en el print, pero al querer armar el listview solo me muestra el primer mensaje y los demás los ignora. Qué estaré haciendo mal? (me fije en muchas publicaciones pero aparentemente está todo bien). Por otro lado no tira errores, solo trae uno y los demás no los tiene en cuenta.
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>