Data is not displayed in the ListView but if it is seen that it is full

3
public class FillList extends AsyncTask<String, String, String> {
        String z = "";
        ListView lstpoints = (ListView) findViewById(R.id.lstpoints);
        List<Map<String, String>> pointslist  = new ArrayList<Map<String, String>>();

        @Override
        protected void onPreExecute() {
            pbbar.setVisibility(View.VISIBLE);
        }

        @Override
        protected void onPostExecute(String r) {

            pbbar.setVisibility(View.GONE);
            Toast.makeText(MapsPreviosProductor.this, r, Toast.LENGTH_SHORT).show();

            String[] from = { "_id", "Latitud", "Longitud"};
            int[] views = { R.id.lblidpunprepro, R.id.lbllatprepro, R.id.lbllonprepro};
            final SimpleAdapter ADA = new SimpleAdapter(MapsPreviosProductor.this,  pointslist, R.layout.lstpunpreproii, from,  views);

            lstpoints.setAdapter(ADA);

            lstpoints.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
                    HashMap<String, Object> obj = (HashMap<String, Object>) ADA.getItem(arg2);
                    idpoint = (String) obj.get("A");
                    String latitud = (String) obj.get("B");
                    String longitud = (String) obj.get("C");
                    txtlatitud.setText(latitud);
                    txtlongitud.setText(longitud);
                }
            });
        }

        @Override
        protected String doInBackground(String... params) {

            try {
                SQLiteDatabase db = openOrCreateDatabase("SAICoffeeSQL", MODE_PRIVATE, null);
                if (db == null) {
                    z = "Error al conectar con la base de datos";
                } else {
                    String query = "select _id, Latitud, Longitud from TB_previos_productor";
                    Cursor ps = db.rawQuery(query, null);
                    //ArrayList<String> data1 = new ArrayList<String>();
                    ps.moveToFirst();
                    while (ps.moveToNext()){
                       Map<String, String> datanum = new HashMap<String, String>();
                       datanum.put("A", ps.getString(ps.getColumnIndex("_id")));
                       datanum.put("B", ps.getString(ps.getColumnIndex("Latitud")));
                       datanum.put("C", ps.getString(ps.getColumnIndex("Longitud")));
                      pointslist.add(datanum);
                   }
                    z = "Consulta exitosa";
                    db.close();
                    ps.close();
                }
            } catch (Exception ex) {
                z = "Error al obtener los valores de las tabla";
            }
            return z;
        }
    }

              

    
asked by Mark Dev 26.05.2016 в 00:15
source

1 answer

0

Although you mention it, it ensures that the "views" list actually has values, if so, you also need to call the notifyDataSetChanged() method; of your Adapter:

 listview.setAdapter(adapter);
 adapter.notifyDataSetChanged();

According to your code within onPostExecute() of your Asynctask would be:

 lstpoints.setAdapter(ADA);
 ADA.notifyDataSetChanged();
  • Another case that comments @KubaHc is, when you are sure you have all data and run notifyDataSetChanged() to fill your adapter, sometimes you do not see when the text is the same color as the background of ListView .
answered by 26.05.2016 / 00:24
source