Skip to content

Instantly share code, notes, and snippets.

@sankarganesh
Created April 17, 2012 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankarganesh/2407640 to your computer and use it in GitHub Desktop.
Save sankarganesh/2407640 to your computer and use it in GitHub Desktop.
Travese the child values according to Parent
/* In forward Navigation , index is a variable and automatically incremented when you swipes it , pos_po it is a position pointer variable , which says you have to pick first child or second child
*/
Class Helper{
public static int temp_child =0,temp_parent=0;
/*
Parent -> Child
120 -> 1
121 -> 2, 3
122 -> 4, 5
123 -> 6, 7
124 -> 8, 9
125 -> 10, 11
126 -> 12, 13
127 -> 14, 15
128 -> 16, 17
129 -> 18, 19
130 -> 20 , 21
Parent Array List has 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130 */
/* I have hard coded the parent id array list values as well child arraylist values because these coming dynamically from JSON */
ArrayList<Integer> parent_arraylist = new ArrayList<integer>();
ArrayList<Integer> child_arraylist = new ArrayList<integer>();
parent_arraylist.add(120); // similarly add 121, 122, 123, 124, 125, 126, 127, 128, 129, 130
child_arraylist.add(1);// simlarly add 2, 3, 4, 5, 6, 7, 8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18 , 19, 20 , 21
// Array list values are loaded
public static int getChild(index){
if(parent_arraylist(index).size !=2){
/*
this will tell us how many child your parent has in the first case only one child i mean for the parent 120 , it has only one child 1 alone
*/
index +=1; // incremented because we have to traverse next child because this parent has only one value
pos_pointer =0;
temp_child = child_arraylist.get(pos_pointer);
return temp_child;
]
else {
if(pos_pointer == 0) {
temp_child = child_arraylist.get(pos_pointer);
pos_pointer +=1;
return temp_child;
}
else{
temp_child = child_arraylist.get(pos_pointer);
pos_pointer -=1;
index + =1;
return temp_child;
}
}
/* Backward direction */
if(parent_arraylist(index) ==2){
if(pos_pointer == 0){
pos_pointer =1;
temp_child= child_arraylist.get(pos_pointer);
return temp_child;
}
else{
pos_pointer=0;
temp_child= child_arraylist.get(pos_pointer);
return temp_child;
}
}
} // end of the method
} // end of the Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment