Reputation: 9
i have a question! Why is my paramView = new Handler(); in red? My error log is error: incompatible types: Handler cannot be converted to View
.
How can i fix it?
public void startTimer(final View paramView)
{
paramView = new Handler();
Timer localTimer = new Timer();
this.timerTask = new TimerTask()
{
public void run()
{
paramView.post(new Runnable()
{
public void run()
{
((TextView)MainActivity.this.findViewById(R.id.timer)).setText(MainActivity.this.myTimer + "");
MainActivity localMyActivity = MainActivity.this;
localMyActivity.myTimer += 1;
}
});
}
};
localTimer.schedule(this.timerTask, 0L, 10L);
}
Please help me to fix the Problem
Upvotes: 0
Views: 69
Reputation: 15668
paramView = new Handler();
This is wrong becuase paramView is a View
, not a handler. A View cannot be cast to a Handler
, nor do they have anything in common so to speak. One is used to show something on the UI, the other on to do something.
Upvotes: 0