Android 在编辑文本中单击按钮时显示递增的数字。
当我点击“添加”按钮时,它会从0开始计数,并一个接一个地显示,但当我点击时 删除按钮它清除编辑文本,但当开始在添加按钮中再次单击时,它会从最后一个数字开始计数,它会停止在它上,因此我希望每次单击它时,它都会从(0)开始计数Android 在编辑文本中单击按钮时显示递增的数字。,android,android-edittext,Android,Android Edittext,当我点击“添加”按钮时,它会从0开始计数,并一个接一个地显示,但当我点击时 删除按钮它清除编辑文本,但当开始在添加按钮中再次单击时,它会从最后一个数字开始计数,它会停止在它上,因此我希望每次单击它时,它都会从(0)开始计数 您必须将数字变量设置为全局变量才能使代码正常工作 只要您单击按钮,它将始终初始化为1 add.setOnClickListener(new View.OnClickListener() { // make it global or store
您必须将数字变量设置为全局变量才能使代码正常工作 只要您单击按钮,它将始终初始化为1
add.setOnClickListener(new View.OnClickListener() {
// make it global or store in intent to retain its value after incrementing and intialize it globally and not here else again will be same case.
// number = 1;
public void onClick(View v) {
// TODO Auto-generated method stub
// random = random();
edit.setText("" + number++); // i want when i click on it in every single time it beginning to count from( 0 )
//because when i delete it and start to click again on add button it count from the last number that stop on it
}
});
谢谢你的重播,但是你能给我一个这个全局变量或意图存储的ex代码吗//首先初始化,使其不包含任何ID。单击按钮后,立即复制ID并继续递增。这个变量应该在类级别。
add.setOnClickListener(new View.OnClickListener() {
// make it global or store in intent to retain its value after incrementing and intialize it globally and not here else again will be same case.
// number = 1;
public void onClick(View v) {
// TODO Auto-generated method stub
// random = random();
edit.setText("" + number++); // i want when i click on it in every single time it beginning to count from( 0 )
//because when i delete it and start to click again on add button it count from the last number that stop on it
}
});