android - passing genric class as fragment -
i creating utility class pass class name extends fragment. fragment method not available in method declaration. code snippet return fragment tag.
private string createfragmenttag(class<? extends fragment> aclass, boolean addargs) { stringbuilder stringbuilder = new stringbuilder(); stringbuilder.append(aclass.getclass().getsimplename()); if(addargs) { stringbuilder.append("-"); **//here argument not calling** if (aclass.getarguments() != null) stringbuilder.append(aclass.getarguments().tostring()); } return stringbuilder.tostring(); }
private string createfragmenttag(fragment fragment, boolean addargs) { stringbuilder stringbuilder = new stringbuilder(); stringbuilder.append(fragment.getclass().getsimplename()); if(addargs) { stringbuilder.append("-"); **//here argument not calling** if (fragment.getarguments() != null) stringbuilder.append(fragment.getarguments().tostring()); } return stringbuilder.tostring(); }
would work. mentioned in comments, aclass
doesn't have getarguments()
method because haven't instantiated class represents yet. if instead pass actual instantiated fragment
class parameter, can accomplish actual goal of generating unique string tag fragment.
Comments
Post a Comment