I have an Android app in which I use Preferences. I am currently developing a custom Preference that uses a TimePicker for its View.
The method that is supposed to give Android the View to show is getView(View, ViewGroup). Its first parameter, View convertView contains a View to reuse if possible.
However, I was thinking of creating the TimePicker in the constructor and storing it in a field:
public class MyPreference {
private TimePicker mTimePicker;
public MyPreference(Context context, AttributeSet attrs) {
super(context, attrs);
mTimePicker = new TimePicker(context);
}
public View getView(View convertView, ViewGroup parent) {
return mTimePicker;
}
}
Are there any problems with this approach, or what would be better?