btnOpen.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast.makeText(getBaseContext(),
"Time selected:" +
timePicker.getCurrentHour() +
":" + timePicker.getCurrentMinute(),
Toast.LENGTH_SHORT).show();
}
});
How to convert this to non-anonymous inner class?
You’d simply need to make it an inner class:
Note the use of
getBaseContext()which will actually be called on the instance of the creating class.If
timePickeris a local variable in your method (as opposed to an instance variable in the creating class) you’d need to pass that into a constructor of the inner class.