I have a problem in my application. My listview is filled with data coming from parse.com, but when the user is not connected to the internet, the listview is empty. I would not have a way to save the adapter of listview while the user is online to display the listview offline?
I tried in various ways and read the parse.com documentation, but to no avail. Here is my code.
public class Eventos extends ActionBarActivity {
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
ListViewEventos adapter;
private List<GetEventos> eventos_lista = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eventos);
new RemoteDataTask().execute();
}
// RemoteDataTask AsyncTask
private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(Eventos.this);
// Set progressdialog title
mProgressDialog.setTitle("Carregando Dados...");
// Set progressdialog message
mProgressDialog.setMessage("Aguarde...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
// Create the array
eventos_lista = new ArrayList<GetEventos>();
try {
// Localizando a classe noticias no parse.com
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
"Eventos");
//colocando por ordem de data
query.orderByAscending("Number");
ob = query.find();
for (ParseObject titulo : ob) {
// Localizando as imagens na coluna foto do parse
ParseFile image = (ParseFile) titulo.get("Foto");
ParseFile img = (ParseFile) titulo.get("FotoEvento");
GetEventos eventos = new GetEventos();
eventos.setTitulo((String) titulo.get("Titulo"));
eventos.setDescricao((String) titulo.get("Descricao"));
eventos.setTextoEvento((String) titulo.get("TextoEvento"));
eventos.setFoto(image.getUrl());
eventos.setFotoEvento(img.getUrl());
eventos_lista.add(eventos);
}
} catch (ParseException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// Locate the listview in listview_main.xml
listview = (ListView) findViewById(R.id.listViewEventos);
// Pass the results into ListViewAdapter.java
adapter = new ListViewEventos(Eventos.this,
eventos_lista);
// Binds the Adapter to the ListView
listview.setAdapter(adapter);
// Close the progressdialog
mProgressDialog.dismiss();
}
}
}