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.
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
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
}
});
I have certain edit text fields. I save the data entered in these fields to my database, which opens in another activity.
But I have a problem when I navigate back to the first activity (Using the back button on the hardware of the emulator) to add next record, the edit field data is retained.
I tried onPause() and myEditText.setText("") also. But the dat simple clears off the edit fields but as soon as I click the fields to enter data again the previous data reappears.
I also tried using finish() and everything works except I have to go through all the activities again to enter the data.
Try this one also.
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String uid=editText1.getText().toString();
String pwd=editText2.getText().toString();
editText1.setText("");
editText2.setText("");
}
});
}
Just to make sure that I understood you clearly. You enter text in EditText boxes. Then press a button which takes you to a new activity. But, when you go back to the old activity the text in the EditText boxes doesn't get clear. Try to do editText.setText(""); when you click the button. I know you said that you tried it, but did you try it inside the function which listens for the button click?
public EditText editText;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText)findViewById(R.id.editText1);
editText.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// As soon as button is clicked, set is as empty
editText.setText("");
}
Try and see if it makes a difference.
you can use this library to clear text by a clear icon
http://droidparts.org/widgets.html#clearableedittext
Use this:
editText.getText().clear();
after onclick of any action do below step
((EditText) findViewById(R.id.yoursXmlId)).setText("");
or else
write this in XML file
EditText
android:hint="Enter Name" />
i did this way.try
You can use:
myEditText.setText(null);
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();
}
}
After making an auto complete text view once the user click the OK button(which i made) i wanted the application to display the contents of selected text in auto complete as a button or as a text view..I find only Toast class for this..which will last only for a short time..Is there any other way of doing it??
OK, fjust write onClick method in OnClickListener as
btnOk.setOnClickListener(new View.OnClickListener(){
public void onClick(View view)
{
String text=mEdit.getText();
mText.setText(text);
}
});