I have been working on passing an edit text value to a string so I can upload the input to my database, but after a lot of time working I have figured out how to do this by pressing enter on the keyboard. I also have a button for uploading the string and I want to have only the button involved, so the upload button will be enter also.
Here is my button:
submit.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
postData();
}
});
Here is the key press enter command:
enter.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
name = enter.getText().toString();
return true;
}
return false;
}
});
Here is where I am using the converted string called name:
nameValuePairs.add(new BasicNameValuePair("username", name));
So I want to get rid of the need for the user to press enter before pressing the submit button, so pressing upload will take care of the enter key press code. I tried creating a method to simulate this being pressed but it didn’t work, and researching didn’t show me a possible way to assign a key press to a button on click.
Any suggestions would be appreciated.
Thanks.
you can try this to perform press button