Determining the currently pointed to item in a list

后端 未结 2 1450
借酒劲吻你
借酒劲吻你 2021-01-21 20:59

I am working with lists. I have been able to determine the first and last position of items in my list. I am using getPostion and displaying item name through a

2条回答
  •  情书的邮戳
    2021-01-21 21:26

    I would add

    public int current; 
    

    to the listoftrees. in the constructor set it to 0;

    Then create a method to return the current fruit_trees object

    public fruit_trees getCurrent()
    {
        fruit_trees ft = first_tree;
        int i = 0;   
        while(i != current)
        {
           ft = ft.next_tree;
           i++;
        }
        return ft;
     }
    

    now this method returns the current and not the next object. So you have 2 options in the next button event.
    the quesiton here is do you want to move to the next tree object every time the button is clicked? if so increment the current property and then call getcurrent to display. If you want the current to be retained and not move (i.e. clicking next over and over will result in the same thing) then display getcurrent().next_tree.tree_type with no increment to current.

提交回复
热议问题