Android: EditText and Button; when click Button, unfocus EditText and hide soft keyboard?
Date : March 29 2020, 07:55 AM
seems to work fine , You can hide the keyboard by calling this. InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);
|
Android add edittext field on click of (+) button and remove by click of (-)
Date : March 29 2020, 07:55 AM
will help you I am creating a add contact activity. There will be only one edit text and a button (+), when click on button then another edit text should be added and previous button should change into (-). By this method i want to add and remove edit text fields. Some thing like this. I am doing like this but not able to achieve that i want. Any idea? private void addEditView() {
// TODO Auto-generated method stub
LinearLayout li=new LinearLayout(this);
EditText et=new EditText(this);
Button b=new Button(this);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int pos=(Integer) v.getTag();
mainLayout.removeViewAt(pos);
}
});
b.setTag((mainLayout.getChildCount()+1));
}
|
create N number of Edittext on button click
Tag : android , By : Richard Laksana
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Finally i found solution which is very simple and small.Now the following code creates N number of edittexts and also get the value from those edittexts created. private LinearLayout mLayout;
private EditText mEditText;
private Button mButton;
int k = -1;
int flag;
int ss=0;
ArrayList<String> applnserverinstnos = new ArrayList<String>();
public static EditText textView[] = new EditText[100];
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mLayout = (LinearLayout) findViewById(R.id.linearLayout);
mEditText = (EditText) findViewById(R.id.editText);
mButton = (Button) findViewById(R.id.button);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try
{
k++;
flag=k;
final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, 50);
lparams.setMargins(20, 20, 20, 0);
textView[flag] = new EditText(AddEditBoxActivity.this);
textView[flag].setLayoutParams(lparams);
textView[flag].setId(flag);
}
catch(Exception e)
{
e.printStackTrace();
}
mLayout.addView(textView[flag]);
}
});
Button b2= (Button)findViewById(R.id.button1);
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
for(int i = 0;i<=k;i++)
{
System.out.println("edit values"+ss+"......"+ textView[i].getText().toString());
}
}
});
}
|
How to hide a button on editText click in Android?
Date : March 29 2020, 07:55 AM
seems to work fine I want to hide a button when I click on editText in Android. Initially I was using the following code , Try using setOnTouchListener instead: editText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
button.setVisibility(View.INVISIBLE);
return false;
}
});
|
Getting a Fragment Dialog to appear after first click on EditText Android Studio
Date : March 29 2020, 07:55 AM
Does that help Right now you are using onClick() instead of it you have to use setOnFocusChangeListener() this event will fire ASAP when your EditText gain focus. Example editText.setOnFocusChangeListener(
new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if(!hasFocus){
// show dialog here
}
}
});
|