Android keyboard appear automatically - android

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

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

setting edit text visible each time button is pressed

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

How to hide the keyboard, and add text to EditText

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");
}
});

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