Reputation: 4948
I was wondering if it is possible and if so how, to create a constructor that takes three variables but will not through an error if the last two are not passed?
something like:
public void onCreate(Bundle savedInstanceState, String s1<non essential>)
{
Upvotes: 2
Views: 113
Reputation: 10891
I really like dash1e's answer best. Luis Miguel Serrano has some excellent additional suggestions.
In addition - if appropriate - you can use varargs
public MyCreate(Bundle savedInstanceState, String ... args)
which has the same effect as
public MyCreate(Bundle savedInstanceState, String [ ] args )
it is very similar to Luis Miguel Serrano of using a List but you don't have to go to the hassle of creating a List.
Upvotes: 0
Reputation: 7807
Create more contructors
public MyCreate(Bundle savedInstanceState)
{
public MyCreate(Bundle savedInstanceState, String s1)
{
public MyCreate(Bundle savedInstanceState, String s1, String s2)
{
try to read this article on constructor overloading.
Upvotes: 12
Reputation: 5099
You have multiple ways of doing this. To name a few:
Upvotes: 0