I use eclipse and I need a solution for my Android-App.
In this App there is an EditText. Its inputType is set to number. If the user writes something into this box and presses the button "Done" next to the numerical pad, the number is shown and the keyboard quits. But my aim is to use this "Done"-button for a simple additional task. By clicking this button I want the number written int the EditText saved in an integer variable. I know how to use buttons by checking or using the id but I don't know (how to get) the Id of this special "Done"-Button.
Could someone help me?
Use this code
EditText editetext = (EditText) findViewById(R.id.editetext); // change this R.id.editetext to your EditText id
Button doneButton = (Button) findViewById(R.id.doneButton); // change this R.id.doneButton to your Button id
doneButton .setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int num = Integer.parseInt(editetext.getText.toString);
}
});
Update
Try this to get done button action in keyboard
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// do any thing here
}
return false;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.