2014-02-22 42 views
0

我想每10秒刷新一次適配器。我正在加載我的ListViewAdapter裏面Handler,所以我該怎麼辦?我如何使用Timer?我希望當價值發生變化時,Adapter會自動刷新ListView如何在Handler中使用Timer?

 @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); 

回答

0
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); 
+0

IM USINF此檢查如果(msg.what == 1){HOW我WRITE INSIDE本聲明??? – user3332060

+0

檢查我編輯的答案 –

+0

現在檢查我的代碼,告訴我如何根據我的代碼調整我的代碼?你使用final來聲明處理器 final Handler handler = new Handler(); – user3332060

相關問題