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
Related
Actually I want that each time I press the button 2 edit text is set visible,and same thing should happen each time the button is pressed.
Basically whenever user presses the button 2 edittext should appear(any loop concept?)
Please suggest.ThankYou :)
Just add a click listener to the button, and change the visibility of editText into it :
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editTextName.setVisible(true);
}
});
Not sure if i got your question right but you can use android:setvisibility=gone in xml editext fields and then in your button onclick use
edittext.setVisibility(View.VISIBLE);
to make the edittext fields visible.
Just set the initial visibility in the code or in the xml to GONE
and then add onClickListener
android:visibility="gone"
//or
btn2.setVisibility(View.GONE)
btn2.setOnClickListener(new View.OnClickListener(){
e#Override
public void onClick(View view) {
editText.setVisible(true);
}
});
You want to populate an edittext each time a button is pressed ?
Create a layout for your edittext:
public EditText createEditText() {
final LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
final EditText edittext = new EditText(this); Editext.setLayoutParams(lparams);
return edittext; }
And then add edittexts to your layout:
rl.addView(createEditText());
If I understand correctly, you want to set edit text to visible on the press of a button. This can be done by following steps:
In your Main Class:
Create 2 new EditText variable:
EditText myEditText1;
EditText myEditText2;
Create a new method to be called on button click:
void buttonClick(View view){
//Get References
myEditText1 = (EditText) findViewById(R.id.first_edit_text);
myEditText2 = (EditText) findViewById(R.id.second_edit_text);
//Set visible
myEditText1.setVisibility(View.VISIBLE);
myEditText2.setVisibility(View.VISIBLE);
//Set edit texts to empty string to reset ("Recreation")
myEditText1.setText("");
myEditText2.setText("");
}
In your xml:
Add the onClick attribute to your Button:
android:onClick="buttonClick";
Add the id to your EditTexts:
android:id="#+id/first_edit_text"
android:id="#+id/second_edit_text"
Now, Whenever the button is pressed, the Edit Text becomes visible, no loop is required. And if you also want to be hidden before pressing button, add:
android:visibility="invisible"
Sources: setVisibility, onClick
Am creating a calculator,i want when button is pressed for example say 5,how to set value 5 to the button and if that button is clicked . The value should be printed in edit text!!
My source code:
ed=(EditText)findViewById(R.id.editText);
b=(Button)findViewById(R.id.button);
gt=Double.parseDouble(ed.getText().toString());
ed.setText(""+gt);
}
If I understand your question correctly:
U got some buttons with text or digits.
And if someone presses one of those buttons u want to display the text of the button in your editText box?
If so u can do something like the following:
EditText myEditText = (EditText) findViewById(R.id.editText);
Button myButton0= (Button) findViewById(R.id.button0);
myButton0.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
//Get the button text and display it in the editText
//This will replace all text in the editText box
myEditText.setText(myButton0.getText().toString());
//Or (Thanks to #cherry-wave)
//This will append the text, instead of replacing
myEditText.setText(myEditText.getText() + myButton0.getText().toString());
}
});
Or (to handle all your buttons with only one method):
Add the following line to all your buttons in your layout xml:
android:onClick="onClick"
And place the following method in your activity class file:
//Your onClick method
public void onClick(View v) {
Button myButton = (Button)v;
//Don't forget to declare your edittext
//This will replace all text in the editText box
myEditText.setText(myButton.getText().toString());
//Or (Thanks to #cherry-wave)
//This will append the text, instead of replacing
myEditText.setText(myEditText.getText() + myButton.getText().toString());
}
Hope this helps u out.
Take the value from button and add to edittext .
Just like this .
editText.setText(btnFive.getText().toString());
Before button click get value from editText .
String edtValue = editText.getText.toString();
Than set editText.setText(edtValue+btnFive.getText().toString());
I have a EditText and a Button .
When you press EditText , I want to not show the keyboard , And when you press the Button, I want to type a number 1 on the EditText .
observation
I want to cursor does not disappear .
![
When you press the 1 1 writes
When you press the Del licked
Can be controlled in the text
Without the appearance of the keyboard ]1
Set this in your EditText xml to disable the keyboard
android:focusableInTouchMode="false"
Set a "1" on your edit text.
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mYourEditText.setText("1");
}
});
Next configuration to your EditText:
android:longClickable="false"
android:clickable="false"
android:focusableInTouchMode="false"
Add a onClickListener to your button:
myButton.setOnClickListener(new View.OnCLickListener(){
#Override
public void onClick(View v) {
myEditText.setText( myEditText.getText().toString() + "1");
}
});
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 disabeld EditText and an "Edit name" button next to it. I press the "Edit name" button and after i make the EditText enabled again i'd like for the keyboard to popup so the user can insert the text (without him needing to "click" the EditText because i'm using that action for saving what he just entered and making the EditText disabled again).
How can this be accomplished?
Thanks,
Andrei
in the textView onclick method put this code.
TextView text = (TextView)findViewById(R.id.youris);
text.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
EditText et = (EditText)findViewById(R.Id.yourid);
et.requestfocus();
}
}