Clicking a Button if a text field contains “r” / carriage return
up vote
-1
down vote
favorite
i am absolutely new to Android development, i have found one example i am learning from.
i want to perform a Button Click or in this Case: onClickDone
when a r
/ carriage return was in the inputTitle Textbox.
the function is at the
/app/src/main/java/com/hazmirulafiq/androidsqlitedatabasedemo/AddItem.java
file
here is the source: Code
is there a uncomplicated way to accomplish this ?
or can someone help me get on the way ?
many thanks in advance

add a comment |
up vote
-1
down vote
favorite
i am absolutely new to Android development, i have found one example i am learning from.
i want to perform a Button Click or in this Case: onClickDone
when a r
/ carriage return was in the inputTitle Textbox.
the function is at the
/app/src/main/java/com/hazmirulafiq/androidsqlitedatabasedemo/AddItem.java
file
here is the source: Code
is there a uncomplicated way to accomplish this ?
or can someone help me get on the way ?
many thanks in advance

add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
i am absolutely new to Android development, i have found one example i am learning from.
i want to perform a Button Click or in this Case: onClickDone
when a r
/ carriage return was in the inputTitle Textbox.
the function is at the
/app/src/main/java/com/hazmirulafiq/androidsqlitedatabasedemo/AddItem.java
file
here is the source: Code
is there a uncomplicated way to accomplish this ?
or can someone help me get on the way ?
many thanks in advance

i am absolutely new to Android development, i have found one example i am learning from.
i want to perform a Button Click or in this Case: onClickDone
when a r
/ carriage return was in the inputTitle Textbox.
the function is at the
/app/src/main/java/com/hazmirulafiq/androidsqlitedatabasedemo/AddItem.java
file
here is the source: Code
is there a uncomplicated way to accomplish this ?
or can someone help me get on the way ?
many thanks in advance


edited 2 days ago
asked 2 days ago
user982998
3417
3417
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
I think you might be looking for a TextWatcher. You can assign it to an EditText:
inputTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if(str.length() > 0 && str.charAt(str.length() - 1) == 'n') {
//Run the onClick code here
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
add a comment |
up vote
0
down vote
I think that changing the if/else statemend can do the trick.
Actually an empty TextBox is empty when there is no text, that's correct.
But what if you try using the string method contains('n);
after getText()
?
public void onClickDone(View view) {
String myInputTitle = inputTitle.getText().toString();
String myInputDesc = inputDesc.getText().toString();
if (myInputTitle.isEmpty() || myInputDesc.isEmpty() || !myInputTitle.getText().toString().contains('n')) {
Snackbar.make(view, "Please fill in both form!",
Snackbar.LENGTH_SHORT).show();
} else {
dbManager.insert(myInputTitle, myInputDesc);
Intent intent = new Intent(AddItem.this,
MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I think you might be looking for a TextWatcher. You can assign it to an EditText:
inputTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if(str.length() > 0 && str.charAt(str.length() - 1) == 'n') {
//Run the onClick code here
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
add a comment |
up vote
1
down vote
accepted
I think you might be looking for a TextWatcher. You can assign it to an EditText:
inputTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if(str.length() > 0 && str.charAt(str.length() - 1) == 'n') {
//Run the onClick code here
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I think you might be looking for a TextWatcher. You can assign it to an EditText:
inputTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if(str.length() > 0 && str.charAt(str.length() - 1) == 'n') {
//Run the onClick code here
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
I think you might be looking for a TextWatcher. You can assign it to an EditText:
inputTitle.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String str = s.toString();
if(str.length() > 0 && str.charAt(str.length() - 1) == 'n') {
//Run the onClick code here
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
edited 2 days ago
answered 2 days ago
Kosovir
417
417
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
add a comment |
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Hi! this has to be at the onCreate area or above at the public class?
– user982998
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
Inside onCreate, after dbManager.open(); line
– Kosovir
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
thank you, that has worked for me :)
– user982998
2 days ago
add a comment |
up vote
0
down vote
I think that changing the if/else statemend can do the trick.
Actually an empty TextBox is empty when there is no text, that's correct.
But what if you try using the string method contains('n);
after getText()
?
public void onClickDone(View view) {
String myInputTitle = inputTitle.getText().toString();
String myInputDesc = inputDesc.getText().toString();
if (myInputTitle.isEmpty() || myInputDesc.isEmpty() || !myInputTitle.getText().toString().contains('n')) {
Snackbar.make(view, "Please fill in both form!",
Snackbar.LENGTH_SHORT).show();
} else {
dbManager.insert(myInputTitle, myInputDesc);
Intent intent = new Intent(AddItem.this,
MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
add a comment |
up vote
0
down vote
I think that changing the if/else statemend can do the trick.
Actually an empty TextBox is empty when there is no text, that's correct.
But what if you try using the string method contains('n);
after getText()
?
public void onClickDone(View view) {
String myInputTitle = inputTitle.getText().toString();
String myInputDesc = inputDesc.getText().toString();
if (myInputTitle.isEmpty() || myInputDesc.isEmpty() || !myInputTitle.getText().toString().contains('n')) {
Snackbar.make(view, "Please fill in both form!",
Snackbar.LENGTH_SHORT).show();
} else {
dbManager.insert(myInputTitle, myInputDesc);
Intent intent = new Intent(AddItem.this,
MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
add a comment |
up vote
0
down vote
up vote
0
down vote
I think that changing the if/else statemend can do the trick.
Actually an empty TextBox is empty when there is no text, that's correct.
But what if you try using the string method contains('n);
after getText()
?
public void onClickDone(View view) {
String myInputTitle = inputTitle.getText().toString();
String myInputDesc = inputDesc.getText().toString();
if (myInputTitle.isEmpty() || myInputDesc.isEmpty() || !myInputTitle.getText().toString().contains('n')) {
Snackbar.make(view, "Please fill in both form!",
Snackbar.LENGTH_SHORT).show();
} else {
dbManager.insert(myInputTitle, myInputDesc);
Intent intent = new Intent(AddItem.this,
MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
I think that changing the if/else statemend can do the trick.
Actually an empty TextBox is empty when there is no text, that's correct.
But what if you try using the string method contains('n);
after getText()
?
public void onClickDone(View view) {
String myInputTitle = inputTitle.getText().toString();
String myInputDesc = inputDesc.getText().toString();
if (myInputTitle.isEmpty() || myInputDesc.isEmpty() || !myInputTitle.getText().toString().contains('n')) {
Snackbar.make(view, "Please fill in both form!",
Snackbar.LENGTH_SHORT).show();
} else {
dbManager.insert(myInputTitle, myInputDesc);
Intent intent = new Intent(AddItem.this,
MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
answered 2 days ago
b00leant
468
468
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373356%2fclicking-a-button-if-a-text-field-contains-r-carriage-return%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown