I want to refresh an adapter every 10 seconds. I'm loading my ListView
Adapter
inside Handler
, so what do I do? How do I use Timer
? I want that whenever the value changes, the Adapter
automatically refreshes ListView
.
@SuppressLint("HandlerLeak")
Handler handle = new Handler() {
public void handleMessage(android.os.Message msg) {
super.handleMessage(msg);
CommonObjects.hideProgress();
if (msg.what == 1) {
plotadapter = new PlotsAdapter(Plots.this, arrayplot);
plotslist.setAdapter(plotadapter);
}
if (msg.what == 2) {
Toast.makeText(Plots.this, "Server, Not Available!",
Toast.LENGTH_SHORT).show();
finish();
}
}
};
@Override
protected void onRestart() {
if(CommonObjects.getLogoutreject().equals("1") && CommonObjects.logout){
// CommonObjects.logout=false;
finish();
}
super.onRestart();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.plots);
plotslist = (ListView) findViewById(R.id.plotslist);
back = (ImageView) findViewById(R.id.plotback);
bottomlayout = (RelativeLayout) findViewById(R.id.bottom_layout);
scroll_down = (ImageView) findViewById(R.id.down);
scroll_up = (ImageView) findViewById(R.id.up);
plotadapter = new PlotsAdapter(Plots.this, arrayplot);
plotslist.setAdapter(plotadapter);
final Handler handler = new Handler();
handler.postDelayed( new Runnable() {
@Override
public void run() {
if(condition)
{
// your code to check
plotadapter.notifyDataSetChanged();
}
handler.postDelayed(this, 1000);
}
}, 1000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.