dimanche 19 avril 2015

Fetching data one by one from SQLlite databse in android in 3sec interval gap

I'm creating an app where I need to display some quotes which I already stored in SQLLite database associated with my app. I know how to fetch data from database and display it in TextView. I need to fetch the data one by one in 3 sec interval and display it in a TextView. That means in each 3 sec interval the app should display a quote from database.


This is my code. But it's not working!



//code to display quotes in a particular interval
handler = new Handler();
Runnable runable = new Runnable()
{
int currV = 0;
boolean go = true;
@Override
public void run()
{
try
{
if(currV == 21 && go)
go = false;
else if(currV == 0 && !go)
go = true;

if(go)
{
waterquote.setText(quotelist.get(currV).getQuote());
currV++;
}
else
{
currV--;
waterquote.setText(quotelist.get(currV).getQuote());
}
//also call the same runnable
handler.postDelayed(this, 3000);
}
catch (Exception e)
{
// TODO: handle exception
}
finally
{
//also call the same runnable
handler.postDelayed(this, 3000);
}
}
};
handler.postDelayed(runable, 3000);

Aucun commentaire:

Enregistrer un commentaire