I want to call multiple methods in a string according to the for
loop condition.
This code should help you understand what I am looking for:
public void onItemClick(View view, int position) {
for (count=0;count<=25;count++){
if (count==position){
String methodCall="A"+count+"List()";
A0List()=methodCall;
}
}
}
A0List(){
//Body
//when count=0 this method is called
}
A1List(){
//body
//when count=1 this method is called
}
// ...
A25List(){
//body
//when count=25 this method is called
}
I use this code on my Android app to reduce click listener code.
I am looking for a solution which avoids an if-else-if ladder loop.