I have two EditText txtPassword,txtEmail based on radiobutton change event I just hide and show txtPassword field
I just want to change ImeOptions with porgrammatic for that I wrote following code
txtPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtEmail.setImeOptions(EditorInfo.IME_ACTION_NEXT);
but this is not working. When I observe soft-keyboard this shows me done action in txtEmail (just because before radio changed only txtEmail is visible so automatic done appear)
but after manually focous in password field and than after if I observe soft-keyboard with email field it automatic changed it with next imeOptions. I just want if One txtEmail is visible than it have done imeOptions and if txtPassword,txtEmail both are visible than txtEmail have ImeOptions next and in txtPassword it have display done imeOptions. Thanks in advance.
Edit:
radiologin.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group,int checkedId) {
// checkedId is the RadioButton selected
if (checkedId == R.id.radioWithoutPassword) {
txtPassword.setVisibility(View.GONE);
txtEmail.setBackgroundDrawable(getResources().getDrawable(R.drawable.both_corner));
txtEmail.setImeOptions(EditorInfo.IME_ACTION_DONE);
}
else
{
txtEmail.setImeOptions(EditorInfo.IME_ACTION_NEXT);
txtPassword.setImeOptions(EditorInfo.IME_ACTION_DONE);
txtPassword.setVisibility(View.VISIBLE);
txtEmail.setBackgroundDrawable(getResources().getDrawable(R.drawable.top_corner));
}
}
});
Try this,
final EditText passwordEditText = new EditText(this);
final EditText emailEditText = new EditText(this);
RadioButton button = new RadioButton(this);
button.setOnCheckedChangeListener(new RadioButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(isChecked){
passwordEditText.setVisibility(View.INVISIBLE);
emailEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
}else{
emailEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
}
}
});
and set passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); always.
i had the same issue. what worked with me is adding android:singleLine="true"and i dint mention any imeOptions or next focus values. i got the expected result. in first editText keyboard shows next if another editText is visible else it shows done :-p
Related
I want to add check box in my android activity such that when the check box is checked one more editText should appear in the activity..
Please tell me how to do that.
Take 2 EditText and make one's visibility Gone by default. Then check if the checkbox is checked or unchecked! If checked make 2nd EditText's visibility Visible.
Setup a listener which will perform this function..
public void addView(LinearLayout lay, EditText etxt){
lay.addView(etxt);
}
public EditText editText(Context context, int id, LinearLayout.LayoutParams params,int paddings){
EditText ib = new EditText(context);
ib.setId(id);
//ib.setBackgroundResource(Background);
// you can use this for a layout //
ib.setLayoutParams(params);
// you can use padding option by getting an array as argument
ib.setPadding(pad,pad,pad,pad);
return ib;
}
You can use this like:
LinearLayout main = (LinearLayout)findViewById(R.id.layout_main);
// Now Show the EditText inside the View
chkBox= (CheckBox)findViewById(R.id.Check_box);
satView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked){
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
EditText eTxt = editText(context,502/*id here*/,lp,0);
addView(main,eTxt);
}
}
});
i have a problem and i dont know how to fix it .I want to make a basic begginer calculator app.I want only one checkbox to be checkable at time but i cant figure out ,stil can check all .And how can i cast strings from edittext to doubl?.App is not finished yet .
Sorry for english.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.top_fragment);
double result ;
EditText number_1 = (EditText)findViewById(R.id.number_1);
EditText number_2 = (EditText)findViewById(R.id.number_2);
CheckBox add_box = (CheckBox)findViewById(R.id.add_box);
CheckBox subtract_box = (CheckBox)findViewById(R.id.subtract_box);
CheckBox divide_box = (CheckBox)findViewById(R.id.divide_box);
CheckBox product_box = (CheckBox)findViewById(R.id.product_box);
final Button button = (Button)findViewById(R.id.button);
number_1.getText().toString();
number_2.getText().toString();
if(add_box.isChecked())
{
subtract_box.setEnabled(false);
divide_box.setEnabled(false);
product_box.setEnabled(false);
}else if(subtract_box.isChecked())
{
product_box.setEnabled(false);
divide_box.setEnabled(false);
add_box.setEnabled(false);
}else if(divide_box.isChecked())
{
subtract_box.setEnabled(false);
product_box.setEnabled(false);
add_box.setEnabled(false);
}else if(product_box.isChecked())
{
subtract_box.setEnabled(false);
divide_box.setEnabled(false);
add_box.setEnabled(false);
}
}
}
you have to set a listener.
add_box.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Disable or enable what you want here. it will be called when add_box is checked or unchecked.
}
});
Do the same for each checkbox, disabling or enabling what you want.
To convert to String to Double you can do that:
Double value1 = Double.valueOf(number_1.getText().toString());
Make sure its not a null value and can be cast to a double.
You can use try / catch.
You may use RadioButton and RadioGroup instead of Checkboxes.
Radio buttons allow the user to select one option from a set. You should use radio buttons for optional sets that are mutually exclusive.
Official doc of RadioButton:
http://developer.android.com/guide/topics/ui/controls/radiobutton.html
Update:
To convert a String to Double you can do that:
// obtain a reference
EditText number_1 = (EditText)findViewById(R.id.number_1);
// obtain the string value
String number_1String = number_1.getText().toString()
// convert the string value to double value
Double number_1Double = Double.valueOf(number_1String);
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.
I am studying programming in Android and I'm hitting an issue. I have this toggle button and when I input a text and the button is on, the text is starred (passworded, call it whatever you want) and when the button is off, the text is a text. However, I am hitting an issue and I don't see the problem.
The block of code looks like:
toggleCommand.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(toggleCommand.isChecked()){
input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else{
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
I don't see the problem. Can you tell me what did I do wrong and explain?
When I turn on the application.. I type something in and it's passworded. I press the button to uncheck it and the passworded text turns into a text. I press the button again and instead of getting passworded again, the text stays normal.
Here is the working code:
toggleCommand.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View arg0)
{
if (toggleCommand.isChecked())
{
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
}
else
{
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
More info: http://thenewboston.org/watch.php?cat=6&number=27
Programmatically change input type of the EditText from PASSWORD to NORMAL & vice versa
edit: Further explanation on setInputType here: http://developer.android.com/reference/android/text/InputType.html
Try this:
toggleCommand = (ToggleButton)findViewById(R.id.the_id_of_your_togglebutton) ;
toggleCommand.setOnCheckedChangeListener( new OnCheckedChangeListener()
{
#Override
public void onCheckedChanged(CompoundButton toggleButton, boolean isChecked)
{
if(isChecked)
{
input.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
else
{
input.setTransformationMethod(null);
}
}
});
You can read more about it on the documentation.
UPDATE
To make this kind of manipulation, you can use TransformationMethod.
So, to set the text to a hidden password, you must use PasswordTransformationMethod, and to turn it to text again, you just set the TransformationMethod to null, this way, no transformation will be applied to the text.
Hope this helps you.
I am facing problem with enabling an edittext box at initialisation. I have disabled my editbox like so: text_edit.setFocusable(false);
Later, I want to enable the textbox via the click of a checkbox.
The textbox is not being enabled, here is my click event code:
if(((CheckBox) v).isChecked()) {
Toast.makeText(User_name_search .this, "Selected", Toast.LENGTH_SHORT).show();
text_edit.setFocusable(false);
//checkbox.setChecked(false);
} else {
Toast.makeText(User_name_search .this, "Not Selected", Toast.LENGTH_SHORT).show();
text_edit.setFocusable(true);
}
What am I doing wrong?
Since you want to enable/disable the EditText, you should consider use the setEnabled(boolean x) method as described here: http://developer.android.com/reference/android/widget/TextView.html#setEnabled%28boolean%29 (EditText extends TextView).
Hope this helps!
You should use setOnClickListener or setOnCheckedChangeListener for the checkbox, and when somebody clicks, you should change setfocusable.
You have to do the following
Checkbox c1;
EditText e1;
click on check box c1 if
if(c1.isChecked==true)
{
e1.setEnabled(true);
}
else
{
e1.setEnabled(false);
}
In the click listener of the checkbox set the enabled property of the edittext to true. So if checkAbove is your checkbox and textAbove is your editText, the code will look like this..
checkAbove.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CheckBox temp = (CheckBox)view;
if (temp.isChecked()){
textAbove.setEnabled(true);
}else {
textAbove.setEnabled(false);
}
}
});
Also put
android:editable = "false"
for the textAbove view in the xml.