for example, if I have 9 edittext how I can dump the value of a selected edittext and the others not
for example edittext1 = 1, edittext2 = 2, edittext3 = 3, edittext4 = 4, edittext5 = 5, edittext6 = 6, edittext7 = 7, edittext8 = 8, edittext9 = 9
here I want to erase 1 and the other number remains
I need your help
There are two ways:
First method:
edittext1.setText("");
Second method:
edittext1.getText().clear();
You can do this whenever you press a button or select an editText...for example this will clear your editText when you click it
edittext1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edittext1.getText().clear();
}
});
Also, if you want to prevent the software keyboard from popping up just add this when you declare your editText
edittext1.setInputType(InputType.TYPE_NULL);
Happy coding!
When click edittext that time get data and clear that data and also directly to set value on editext box click event.
editText1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
editText1.setText("");
editText1.getText().clear();
}
});
Related
I have one button and 1 edittext. The button is set to "change", and EditText is enable-false. When you click on a button, its text is changed to "save", and edit text is available for input. After a second press, the text changes to "change" again, and the button becomes Enable-false.
how to implement it?
Use this onClickListener on your button -
Button yourButton = (Button) view.findViewById(R.id.button)
EditText yourEditText = (EditText) view.findViewById(R.id.edittext)
yourButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (!yourEdittext.isEnabled()){
yourButton.setText("Save");
yourEditText.setEnabled(true);
counter++;
}else if (yourEdittext.isEnabled()){
yourButton.setText("Change again");
yourButton.setEnabled(false);
}
}
});
Make sure to set the initial button's text and the edit text disabled for the starting point
I have 2 TextView, and 1 Button. I want to be able to click the button and to save the text on the first TextView and show the value on the second TextView.
I've tried this code:
public void buttonOnClick(){
Button submit = (Button) findViewById(R.id.submit);
editName = (EditText) findViewById(R.id.name);
editEmail = (EditText) findViewById(R.id.email);
textout = (TextView) findViewById(R.id.outputText);
submit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
textout.setText(editName.getText()+"\n"+editEmail.getText());
}
});
}
But I get an error on 'textout'. When I clock the red light buble, it says 'create a local variable', field text'.
Try this
public void onClick(View v) {
textout.setText(editName.getText().toString()+"\n"+editEmail.getText().toString());
}
Your problem stimulates from the fact that EditText getText() returns Editable Object. It's not a String and you can't concat 2 Editable Objects.
You have 2 Options:
textout.setText(editName.getText().toString() + "\n" + editEmail.getText().toString());
And Second you can use SpanableStringBuilder
SpannableStringBuilder sb = new SpannableStringBuilder(editName.getText());
sb.append("\n").append(editEmail.getText());
The Second options allows you also to decorate the Text and save you the Need to build a String which is (maybe) better.
I created an Application to dial particular contact number.
It has one EditText and ten buttons for the digits from 0 to 9 and a BACK button.
I want to erase single digit from EditText on each click event of BACK button.
Is there any way to do so ?
Namaskar modiji, try
myButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view){
String text = et.getText().toString();
if(!TextUtils.isEmpty(text)){
String newText = text.substring(1, text.length()); //delete from left
//or
String newText1 = text.substring(0, text.length() - 1); //delete from right
et.setText(newText);
et.setSelection(newText.length());
//or
et.setText(newText1);
et.setSelection(newText1.length());
}
}
}
I am trying to make edittext editable after a button click.
Below is my code snippet.
Before click event:
name_value = (EditText) findViewById(R.id.name_value);
name_value.setText(DashBoardDisplay_l.getName());
name_value.setFocusable(false);
likes_value = (EditText) findViewById(R.id.likes_value);
likes_value.setText(DashBoardDisplay_l.getLikes());
likes_value.setFocusable(false);
calls_value = (EditText) findViewById(R.id.Calls_value);
calls_value.setText(DashBoardDisplay_l.getCalls());
calls_value.setFocusable(false);
After click event:
android.view.View.OnClickListener enable_listeners = new OnClickListener() {
#Override
public void onClick(View v) {
Log.d("Zumbare","in enable listners");
Button b = (Button) v;
if(b.getText().toString().equalsIgnoreCase("edit")){
Log.d("Zumbare","in edit condition");
desc.setOnClickListener(show_buttons);
icon.setOnClickListener(slct_image);
name_value.setFocusable(true);
likes_value.setFocusable(true);
calls_value.setFocusable(true);
edit.setText("Save");
name_value.requestFocus();
}
}
};
But after button click event , no focus is coming on to name_value edittext and also not editable.
so what is wrong i am doing here or anything more to do?
You would need to use setEnabled() for that.
setFocusable() will not make edittext editable. It will just set focus on particular edittext.
// make editable
name_value.setEnabled(true);
likes_value.setEnabled(true);
calls_value.setEnabled(true);
// set focusable
name_value.setFocusable(true);
likes_value.setFocusable(true);
calls_value.setFocusable(true);
//set focus to particular edittext
name_value.requestFocus();
should work in onClick()'s code.
I have a quick question.
I have a screen with some numbers, when you click one of the numbers, the number gets appended to the end of the edittext.
input.append(number);
I also have a backbutton, when the user clicks this button I want to remove the last character.
At the moment I have the following :
Editable currentText = input.getText();
if (currentText.length() > 0) {
currentText.delete(currentText.length() - 1,
currentText.length());
input.setText(currentText);
}
Is there an easier way to do this ? Something in the line of input.remove()?
I realise this is an old question but it's still valid. If you trim the text yourself, the cursor will be reset to the start when you setText(). So instead (as mentioned by njzk2), send a fake delete key event and let the platform handle it for you...
//get a reference to both your backButton and editText field
EditText editText = (EditText) layout.findViewById(R.id.text);
ImageButton backButton = (ImageButton) layout.findViewById(R.id.back_button);
//then get a BaseInputConnection associated with the editText field
BaseInputConnection textFieldInputConnection = new BaseInputConnection(editText, true);
//then in the onClick listener for the backButton, send the fake delete key
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
textFieldInputConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
}
});
try this out,
String str = yourEditText.getText().toString().trim();
if(str.length()!=0){
str = str.substring( 0, str.length() - 1 );
yourEditText.setText ( str );
}