disabled button - android

My problem: I wanna make an activity contains spinner and editBox & button I wanna make the button disabled until the user fill the box and choose an item from spinner.
I wrote it check the if empty it disable the button but when i fill the box the button still disabled..!!the second problem : when I put hint into edite box it read it when check if the box is empty!!
and how can I check the spinner if selected or not ??
*value is the name of editText
*enterBtn is the name of button.
if(x.matches("")){
enterBtn.setEnabled(false);
onStart();
}else {
enterBtn.setEnabled(true);
}
enterBtn.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(Integer.valueOf(x)>(70)){
Value.setText("plz dont enter more than 500");
}else{
........
...}

Use Listener For Edit Box And Spinner..when you enters text to the Edit Text it Does not Check Whether It Has Text Entered Or not..thats why your button gets disabled..hear is the listner where you can actually get when someone entered text to Editext.
tv = (TextView)findViewById(R.id.charCounts);
textMessage = (EditText)findViewById(R.id.textMessage);
textMessage.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
i++;
tv.setText(String.valueOf(i) + " / " + String.valueOf(charCounts));
}
});

Related

EditText and button(When button is pressed value shoud be entered in edittext field)

Am creating a calculator,i want when button is pressed for example say 5,how to set value 5 to the button and if that button is clicked . The value should be printed in edit text!!
My source code:
ed=(EditText)findViewById(R.id.editText);
b=(Button)findViewById(R.id.button);
gt=Double.parseDouble(ed.getText().toString());
ed.setText(""+gt);
}
If I understand your question correctly:
U got some buttons with text or digits.
And if someone presses one of those buttons u want to display the text of the button in your editText box?
If so u can do something like the following:
EditText myEditText = (EditText) findViewById(R.id.editText);
Button myButton0= (Button) findViewById(R.id.button0);
myButton0.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View v) {
//Get the button text and display it in the editText
//This will replace all text in the editText box
myEditText.setText(myButton0.getText().toString());
//Or (Thanks to #cherry-wave)
//This will append the text, instead of replacing
myEditText.setText(myEditText.getText() + myButton0.getText().toString());
}
});
Or (to handle all your buttons with only one method):
Add the following line to all your buttons in your layout xml:
android:onClick="onClick"
And place the following method in your activity class file:
//Your onClick method
public void onClick(View v) {
Button myButton = (Button)v;
//Don't forget to declare your edittext
//This will replace all text in the editText box
myEditText.setText(myButton.getText().toString());
//Or (Thanks to #cherry-wave)
//This will append the text, instead of replacing
myEditText.setText(myEditText.getText() + myButton.getText().toString());
}
Hope this helps u out.
Take the value from button and add to edittext .
Just like this .
editText.setText(btnFive.getText().toString());
Before button click get value from editText .
String edtValue = editText.getText.toString();
Than set editText.setText(edtValue+btnFive.getText().toString());

customization of edit text and input type in android

I had customized edit text with floating label and i write a method to set input type which is working but for last edit text its showing number keyboard instead of normal keyboard take alook at my code
private void setFloatInputType(int inputType) {
if(inputType==16) {
input.setFocusable(false);
input.setOnFocusChangeListener(null);
input.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
setDatePicker();
}
});
}
else
if(inputType==0) {
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
// input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
Log.d("INput TYp3", "" + input.getInputType());
}
else
input.setInputType(inputType);
I had debug the code it showsthat for third text field input type is set to
normal keyboard but os is popup numberic keyboard.
any suggestion will be highly appreciated.
Thanks,
Try replacing
input.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);
with
input.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_NORMAL);

Appending Text to Android TextView but Non-Editable

I want to append text to an android EditText view but I want that text to not be present in the popup editor. To be clear I want to put units in the EditText. So for example "10 gallons" but when the popup editor is displayed I only want to see and edit "10". Then when the value is returned I want the " gallons" appended back on to the view.
Is this possible in an automatic way or do I have to track onTouch() events and have a listener for the keyboard and manually append the units again?
I believe the onFocusChange method for EditText views would detect when a user is editing the text field. Try something like this..
EditText et = (EditText) findViewById(R.id.editText);
et.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean b) {
if (b) {
((EditText)view).setText(String.valueOf(value));
} else {
value = Integer.valueOf(((EditText)view).getText().toString());
((EditText)view).setText(value + " gallons");
}
}
});

Change EditText value from text to password and vice versa on ToggleButton checked

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.

How to put an Edittext with a button below that when I click, it recognizes if it's correct or wrong?

My intention is to put an Edittext, and a Button below, and when the user put an specific word and click the button, the value is correct, and all the other different words are wrong.. How to identify it with codes?
btn.onClickListiner(this);
#Override
public void onClick(View v) {
if (v == btn) {
// check word
String word = editText.getText().toString(); // don't forget "toString()" .
// checking word below :
}}

Categories

Resources