setting edit text visible each time button is pressed - android

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

Related

changing the button text from the edittext state

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

EditText and button(When button is pressed value shoud be entered in edittext field)

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());

Android - setOnkeyListen method how does it work with EditText?

I create a dialog window in an activity, then I put the buttons in this dialog window and listened to them. However, I want to listen to android device found in the back button. and dialog.setOnkeyListen method I used for it. I have put the program by executing dialog window EDITTEXT not enter data into the field. So when I add code to the setOnkeyListen I can not enter data into the EditText field. I hope you know what I mean
If you're asking how to set the OnClickListener for a textview here is an example hope this helps:
TextView textView = (TextView) findViewById(R.id.textView);
textView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
// Code you want to execute on the click goes here
}
});

edittext not getting editable from read only mode dynamically

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.

How to make EditText erase evertime a button is clicked

Okay i have a edit text box that takes user input. Every time the user clicks the button i would like for the text that the user typed to be gone. As of now everytime the button is clicked the text remains in the edittext. I would like the text to be erased by default without having to create a instance of EditText everytime
Thanks guys if you can help!
Use setText():
mEditText.setText("");
after your setContentView:
final EditText yourEditText= (EditText)findViewById(R.id.yourIDEditText);
yourEditText.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View v)
{
yourEditText.setText("");
}
});
With this, every time the user clicks all content is cleaned.

Categories

Resources