I want to create a unique Id with reset button. I have a class ViewId
.ViewId
class contain AtomicInteger
. AtomicInteger
create unique Id successfully.But I want to reset unique Id using a button.So please help me to reset and create unique id again.
ViewId
Class :
import java.util.concurrent.atomic.AtomicInteger;
public class ViewId {
private static ViewId INSTANCE = new ViewId();
private AtomicInteger seq;
private ViewId() {
seq = new AtomicInteger(0);
}
public int getUniqueId() {
return seq.incrementAndGet();
}
public static ViewId getInstance() {
return INSTANCE;
}
}
MainActivity
Class :
public class MainActivity extends AppCompatActivity {
EditText editValue;
ViewId viewId = ViewId.getInstance();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editValue = (EditText)findViewById(R.id.editText);
}
// Increment Button
public void floatIncrement(View view) {
Log.e("Incremented value is : ", String.valueOf(viewId.getUniqueId()));
}
// Reset Button
public void resetBtn(View view) {
// reset here
}
}
floatIncrement
, 2.resetBtn
. I want to store the id in database when I click the increment button. I show the result in log ..thefloatIncrement
btn increment the value(ex : 1,2,3,..).When I clickresetBtn
I want again (1,2,3,...) order .. – Gravely