Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh value

Status
Not open for further replies.

apffal

Technical User
Apr 10, 2004
97
PT
I'm using as variable the integer value of last selected index in a list.
However, after removing all items in my list, with removeAll, I cannot refresh that integer value - which is still used when adding new items to it.
How can I do it?
Thanks.
 
//Do you use ArrayList?
//Do you keep the element with the greatest index?
// my code remove all the elements except the elements with greatest index number.
Code:
import java.util.*;
class mylist
      {
       public static void main(String args[])
              {
               MyArrayList al = new MyArrayList();
               al.add(new Integer("1"));
               al.add(new Integer("2"));
               al.add(new Integer("3"));
               al.removeRangeB(0,al.size()-1);
               System.out.println(al.size());
              }
      }
class MyArrayList extends ArrayList
      {
       public MyArrayList()
              {
               super();
              }
       public void removeRangeB(int a, int b)
              {
               removeRange(a,b);
              }
      }
 
I'm using a simple list (not ArrayList) for storing ResultSet results and using the value of last selected index for navigating through records.
In my first query, everything goes right.
But, when I remove all list items, for trying another query, the navigation skips one or more records/items.
I think the index value is not being refreshed and is still used when adding new items to list.
How can I solve this ?

That's my relevant code :

class Listener1 implements ActionListener {

static int i, x;

public void actionPerformed(ActionEvent ev) {
-------------------------
while (result.previous()) {
String ord = result.getString(1);
lista0.add(ord);
x = lista0.getItemCount()-1;
t0.setText(lista0.getItem(x));
}
--------------------

prev.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
i = x;
i++;
if(i <= lista0.getItemCount()-1){
t0.setText(lista0.getItem(i));
lista0.select(i);
x = lista0.getSelectedIndex();
}
}
});

next.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
i = x;
i--;
if(i >= 0) {
t0.setText(lista0.getItem(i));
lista0.select(i);
x = lista0.getSelectedIndex();
}
}
});

new_search.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
x = -1;
lista0.removeAll();
}
});

}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top