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");
}
});
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
How to implement the method, when the button is clicked, EditText can be edited. Before this, EditText must be closed for text entry.
code located below does not help
Entertext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Total.setFocusable(true);
}
});
Try this use android:focusable="false" in xml to disable your EditText
<EditText
android:id="#+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false" />
now enabled your Edittext inside button click listener using android:focusable like this
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
edittext.setFocusable(true);
edittext.setFocusableInTouchMode(true);
edittext.setEnabled(true);
edittext.requestFocus();
}
});
make edittext in xml as focusable false like below ..
android:focusable="false"
then after click event used below code..
Entertext.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Total.setFocusable(true);
Total.setFocusableInTouchMode(true);
Total.requestFocus();
}
});
you can also used enable and disable concept in edittext.
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
What is the logic of adding text to an edittext when button is pressed. Like in simple calculator, when u press a button the numbers will be shown to the edittext. What do you call that logic? I need a developers explanation.
button.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
edittext.setText("text");
}
});
The logic is get the text from button and set it to the edittext,in aappending mode
Just use append() of the EditText. The Argument will be appended at the end of the Editable.
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
editText1.append("your string to add at the end.");
}
});
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();
}
}