irobotxx
irobotxx

Reputation: 6063

sorting out different handlers android

all, i want to create multiple handlers that gets triggered based on users selection, but this handlers implement the same runnable method. the only difference is that they call different postDelayed() method. how do i go about achieving this without rewriting the same code for the runnable?

i am still not clear about how the handleMessages() works and if it can be used for this?.. thank you

Upvotes: 0

Views: 284

Answers (1)

DeRagan
DeRagan

Reputation: 22920

Use a handler and use a switch case around it. Update the view by sending a message to your handler

Handler Handlerobject;

Handlerobject= new Handler()
{
  public void handleMessage(Message msg) {

  switch(msg.what)
  {
   case 1:
  // Your code to update the UI

   break;

   case 2:
  // Your code to update the UI
   break;           
  }         
}};

Handlerobject.sendEmptyMessage(1) or sendEmptyMessageDelayed

Upvotes: 1

Related Questions