ok so this has been asked many times and I have looked at various answers but still somehow not able to get this right.
Problem: I have some 5 fragments(non android guys please assume classes) which I need to dynamically instantiate based on what is clicked in a list. I get the string in the click handler. I have named my fragments conveniently. So basically one of my fragments is called SearchResults.java and the corresponding item click will return "SearchResults". So I want to do something like:
public void onClick(View v) {
Class cls = Class.forname(clickedString) //clickedString = "SearchResults"
//instantiate it as if it were equal to SearchResults sr = new SearchResults().
}
I just want to avoid if/ else or switch cases and looking for a smarter way. I might be missing some very basic core java concepts. Please help.