PDA

View Full Version : transction numbers




Alvinkiang
May 8, 2006, 03:51 AM
any one knows how i can let my Transaction Id keep on adding when i click new??
the text1[] ius a loop i used to read out all my textField From XML....

should i insert a Loop or ?

public void New(){

text.setText(item[0]+"\n"+item[1]);
text1[0].setText("");
text1[2].setText("");
text1[4].setText("");
text1[6].setText("");
text1[8].setText("T10001");<----- this is the one...
}



jtalerico
May 8, 2006, 06:44 AM
You need something to keep track of how many Transactions have occured. Maybe a transID field. So something along the lines of..

int transID = 10001;
public void New(){

text.setText(item[0]+"\n"+item[1]);
text1[0].setText("");
text1[2].setText("");
text1[4].setText("");
text1[6].setText("");
text1[8].setText("T"+transID.toString());<----- this is the one...
transID++;
}

Everytime you call that method transID will be added to.. Not sure if that is correct code, not sure what you are using. But it should give you and idea on how to do it.

savar
May 8, 2006, 05:58 PM
Wow...what language is this?

I think it would be better if you posted what you're actually trying to accomplish. I suspect you're trying to do something easy the hard way.

Anyway, along the lines of what somebody else said...if you're looking for a way to get unique, sequential integers, you should probably build a separate class to hold that stuff. Keep a private, static integer id in the class and provide a method to fetch the next id. This method will increment the private variable and then return the new value.

Edit: Also, if this is java, then naming a method "New" is a really bad idea.

Alvinkiang
May 8, 2006, 08:59 PM
Wow...what language is this?

I think it would be better if you posted what you're actually trying to accomplish. I suspect you're trying to do something easy the hard way.

Anyway, along the lines of what somebody else said...if you're looking for a way to get unique, sequential integers, you should probably build a separate class to hold that stuff. Keep a private, static integer id in the class and provide a method to fetch the next id. This method will increment the private variable and then return the new value.

Edit: Also, if this is java, then naming a method "New" is a really bad idea.

thanks... i have managed to solve my Problem.. anyway in this func. i was trying to reset my textfeild and at the same time adding on to the next transaction ID