Please guys help me! I'm going crazy ! Below is a brief summary of my code that should be used to make a simple subtraction . Should I just read the amount of SCONTRINO and if you put CONTANTI , the field VINCITE , will have as setText SCONTRINO - CONTANTI , same with VINCITE , will CONTANTI.setText SCONTRINO - VINCITE .
But despite everything seems to be well written , when I insert a field , I StackOverflowError by the two Update methods.
public class AssegnaScontoActivity extends Activity {
TextView contanti;
TextView vincite;
TextView scontrino;
Float contantiFloat;
Float vinciteFloat;
Float scontrinoFloat;
public void onCreate(Bundle savedInstanceState) {
//INIZIALIZZAZIONE ACTIVITTY
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.assegna_sconto_activity_landscape);
//--------------------------
contantiFloat = Float.parseFloat(contanti.getText().toString());
vinciteFloat = Float.parseFloat(vincite.getText().toString());
scontrinoFloat = Float.parseFloat(1000);
contanti = (TextView) findViewById(R.id.contanti);
vincite = (TextView) findViewById(R.id.importo_vincite);
scontrino = (TextView) findViewById(R.id.importo_scontrino);
contanti.addTextChangedListener(new TextChangedListener()
{
#Override
public void numberEntered(Float number)
{
contantiFloat = number;
updateVincite();
}
});
vincite.addTextChangedListener(new TextChangedListener()
{
#Override
public void numberEntered(Float number)
{
vinciteFloat = number;
updateContanti();
}
});
}
private void updateVincite()
{
Float total = scontrinoFloat - contantiFloat; // This is where you apply your function
vincite.setText(""+total); // need to do that otherwise int will
// be treated as res id.
}
private void updateContanti()
{
Float total = scontrinoFloat - vinciteFloat; // This is where you apply your function
contanti.setText(""+total); // need to do that otherwise int will
// be treated as res id.
}
private abstract class TextChangedListener implements TextWatcher
{
public abstract void numberEntered(Float number);
#Override
public void afterTextChanged(Editable s)
{
String text = s.toString();
try
{
Float parsedFloat = Float.parseFloat(text);
numberEntered(parsedFloat);
} catch (NumberFormatException e)
{
Log.w(getPackageName(), "Non si puo' parsare '" + text + "' col numero", e);
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
}
Your code is going into an infinite loop because you are changing the text when afterTextChanged() is called, which causes afterTextChanged() to be called again and so on until eventually you overflow your call stack.
You can stop this by only setting the text inside updateVincite() and updateContanti() if it is different to the current text.
e.g.:
private void updateVincite()
{
Float total = scontrinoFloat - contantiFloat; // This is where you apply your function
String text = ""+total;
if(!vincite.getText().toString().contentEquals(text))
vincite.setText(text); // need to do that otherwise int will
// be treated as res id.
}
and do the same for updateContanti()
First define contanti and vincite .
Change code as follows.
contanti = (TextView) findViewById(R.id.contanti);
vincite = (TextView) findViewById(R.id.importo_vincite);
scontrino = (TextView) findViewById(R.id.importo_scontrino);
contantiFloat = Float.parseFloat(contanti.getText().toString());
vinciteFloat = Float.parseFloat(vincite.getText().toString());
scontrinoFloat = Float.parseFloat(1000);
Related
I want to be able to store the contents of the editText input, then be able to display it in a listview.
I have connected a RFID device that is set in emulator mode. This mode basically also you to scan an RFID tag and the RFID number gets populated where ever the mouse cursor is. In this case it is at the editText input. The lenght of the RFID number is 10, since the RFID number as 10 digits. Once the RFID number is detected I then want to display it on the listview and scan another tag and add that to the listview also.
In my case whenever I code sees the display method the app crashes and I dont know why. Can someone explain to me why this is happening?
epc.add("\n" + etRfidNo.getText().toString() + ", " + DateFormat.getInstance().format(currentDate));
display();```
MainActivity code:
public class MainActivity extends AppCompatActivity {
EditText etRfidNo;
TextView textView;
private Set<String> epc = new HashSet<>();
ArrayAdapter<String> contactAdapter;
String single_epc;
Button scan;
ListView listView;
boolean set = true;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
etRfidNo = (EditText) findViewById(R.id.etRfidNo);
scan = (Button) findViewById(R.id.scan);
TextView textV = (TextView)findViewById(R.id.textView);
etRfidNo.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
//TextView textV = (TextView)findViewById(R.id.textView);
//textV.setText(s); //set text for text view
single_epc = String.valueOf(s);
if(s.length() == 10)
{
Date currentDate = new Date();
epc.add("\n" + etRfidNo.getText().toString() + ", " + DateFormat.getInstance().format(currentDate));
display();
}
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
public void display() {
contactAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<>(epc));
listView.setAdapter(contactAdapter);
}
}
listView = (ListView) findViewById(R.id.listviewID);
Forgot to add this.
I have a program that has 10 images. I want to change the background of each image when the user enters valid text in editText. So basically if user enters valid text in the editText it will change the first image (image 1). If the user enters text again in editText it should change image 2 etc. until image 10.
I have tried to create a list of images and retrieve every element in the image.
I don't know if my logic is wrong
The images are stamp1, stamp2, stamp3, stamp4 ....stamp12
final String Entercode = codeNumber.getEditableText().toString().trim();
Toast.makeText(getApplicationContext(),Entercode,Toast.LENGTH_SHORT).show();
if (Entercode.equals("sweet")){
for (int i = 0; i < stampImageList.size(); i++) {
Object obj = stampImageList.get(i);
stampImageList = new ArrayList();
stampImageList.add(stamp1);
stampImageList.add(stamp2);
stampImageList.add(stamp3);
stampImageList.add(stamp4);
stampImageList.add(stamp5);
stampImageList.add(stamp6);
stampImageList.add(stamp7);
stampImageList.add(stamp8);
stampImageList.add(stamp9);
stampImageList.add(stamp10);
stampImageList.add(stamp11);
stampImageList.add(stamp12);
if (obj == stampImageList.get(2)) {
// stamp4.setBackgroundResource(R.drawable.earned_stamp);
stamp3.setBackgroundResource(R.drawable.earned_stamp);
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setIcon(R.drawable.logo);
builder.setMessage("Stamp Earned");
} else if (obj == stampImageList.get(3)) {
stamp5.setBackgroundResource(R.drawable.earned_stamp);
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setIcon(R.drawable.logo);
builder.setMessage("Stamp Earned");
}
}
} else{
AlertDialog.Builder alert = new AlertDialog.Builder(getApplicationContext());
alert.setIcon(R.drawable.logo);
alert.setTitle("Validation results");
alert.setMessage("validation failed");
}
You should use TextWatcher to EditText.In afterchange method you compare with values.
EditText et = (EditText)findViewById(R.id.editText);
Log.e("TextWatcherTest", "Set text xyz");
et.setText("xyz");
et.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) { }
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
#Override
public void afterTextChanged(Editable s) {
Log.e("TextWatcherTest", "afterTextChanged:\t" +s.toString());//Compare here with stamp1 or like that
}
});
#steve, here I have prepared a code for 10 Drawable Images in your project.
public class Pictures_Activity_stack extends AppCompatActivity {
private String TAG= "Pictures_Activity---";
private ImageView picture;
private EditText text;
private Button validate;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pictures_stack);
picture = (ImageView)findViewById(R.id.picture); //imageview where your picture changes
text = (EditText) findViewById(R.id.text);//edittext where you input text
validate = (Button) findViewById(R.id.button);//button to validate the text and change picture accordingly
// array to store your drawable images
final int pictures[] = {
R.drawable.firstimage,
R.drawable.secondimage,
R.drawable.p3,
R.drawable.p4,
R.drawable.p5,
R.drawable.p6,
R.drawable.p7,
R.drawable.p8,
R.drawable.p9,
R.drawable.p10
};
// click the button to set the image
validate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String input = text.getText().toString(); //input from edittext
if (input.equals("first")) {
picture.setImageResource(pictures[0]); //set first image in array if input=first
Toast.makeText(getBaseContext(),input,Toast.LENGTH_SHORT).show();
}
else if (input.equals("second")) {
picture.setImageResource(pictures[1]);//set first image in array if input=secind
Toast.makeText(getBaseContext(),input,Toast.LENGTH_SHORT).show();
}
// else if (input.equals("third")) {
// // and so on for other string values...
// .................................
// }
else
{
// if your input does not matches any string do this
Toast.makeText(getBaseContext(),"NO MATCHED STRING",Toast.LENGTH_SHORT).show();
}
}
});
}
}
The above code set images according to input in edit Text, when button is clicked.
I am nearly complete with my first android app, which is a basic tip calculator. I am having trouble with line 36
amountDisplayTextView = (TextView) findViewById(R.id.amountDisplayTextView);
I am getting these errors:
Multiple markers at this line
-Syntax error, insert ";" to complete FieldDeclaration
-Syntax error on token ".", ... expected
-Syntax error on token "amountDisplayTextView", VariableDeclaratorId expected after this token
-Return type for the method is missing
-Syntax error on token ")", { expected after this token
-Syntax error on token "amountDisplayTextView", VariableDeclaratorId expected after this token
I have tried to trouble shoot, but I hit a wall. Any assistance is appreciated! Here is the rest of the class.
package com.example.tipcalc;
import java.text.NumberFormat;
import android.app.Activity;
import android.os.Bundle;
import android.text.TextWatcher;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
public class MainActivity extends Activity {
//currency and percent formatters
private static final NumberFormat currencyFormat =
NumberFormat.getCurrencyInstance();
private static final NumberFormat percentFormat =
NumberFormat.getPercentInstance();
private double billAmount = 0.0; //bill amount entered by the user
private double customPercent = 0.18; //initial custom percent value
private TextView amountDisplayTextView; //shows formatted bill amount
private TextView percentCustomTextView;//shows custom tip percentage
private TextView tip15TextView; // shows 15% tip
private TextView total15TextView; // shows total with 15% tip
private TextView tipCustomTextView; // shows custom tip amount
private TextView totalCustomTextView; //shows total with custom tip
//called when activity is first created
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //call superclass's version
setContentView(R.layout.activity_main); //inflate GUI
}
//get references to the TextViews
//that MainActivity interacts with programmatically
amountDisplayTextView = (TextView) findViewById(R.id.amountDisplayTextView);
percentCustomTextView = (TextView) findViewById(R.id.percentCustomTextView);
tip15TextView = (TextView) findViewById(R.id.tip15TextView);
total15TextView = (TextView) findViewById(R.id.total15TextView);
tipCustomTextView = (TextView) findViewById(R.id.tipCustomTextView);
totalCustomTextView = (TextView) findViewById(R.id.totalCustomTextView);
}
//update 15% textviews
private void updateStandard()
{
//calculate 15% tip and total
double fifteenPercentTip = billAmount * 0.15;
double fifteenPercentTotal = billAmount + fifteenPercentTip;
//display 15% tip and total formatted as currency
tip15TextView.setText(currencyFormat.format(fifteenPercentTip));
total15TextView.setText(currencyFormat.format(fifteenPercentTotal));
} //end method updateStandard
//updates the custom tip and total TextViews
private void updateCustom()
{
//show customPercent in percentCustomTextView formatted as %
percentCustomTextView.setText(percentFormat.format(customPercent));
//calculate the custom tip and total
double customTip = billAmount * customPercent;
double customTotal = billAmount + customTip;
//display custom tip and total formatted as currency
tipCustomTextView.setText(currencyFormat.format(customTip));
totalCustomTextView.setText(currencyFormat.format(customTotal));
}//end updateCustom
//called when the user changes the position of SeekBar
private OnSeekBarChangeListener customSeekBarListener =
new OnSeekBarChangeListener()
{
//update customPercent, then call updateCustom
#Override
publicvoid onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{
//set customPercent to position of the SeekBar's thumb
customPercent = progress / 100.0; //update the custom tip TextViews
updateCustom(); //update the custom tip TextView's
}; //end method onProgressChanged
#Override
public void onStartTrackingTouch(SeekBar seekBar)
{
}// end method onStartTrackingTouch
#Override
public void onStopTrackingTouch(SeekBar seekBar)
{
}// end method onStopTrackingTouch
};//end OnSeekBarChangeListener
//event-handling object that responds to amountEditText's events
private TextWatcher amountEditTextWatcher = new TextWatcher()
{
//called when the user enters a number
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
//convert amountEditText's text to a double
try
{
billAmount = Double.parseDouble(s.toString()) / 100.0;
} //end try
catch (NumberFormatException e)
{
billAmount = 0.0; //default if an exception occurs
}//end catch
//display currency formatted bill amount
amountDisplayTextView.setText(currencyFormat.format(billAmount));
updateStandard(); //update the 15% tip Textviews
updateCustom(); //update the custom tip TextViews
}; //end method onTextChanged
#Override
public void afterTextChanged(Editable s)
{
}//end method afterTextChanged
#Override
public void beforeTextChanged (CharSequence s, int start, int count, int after)
{
} // end method before TextChanged
}; //end amountEditTextWatcher
}//end mainActivity class
its all about your {}{} your declaring your variables at class level and trying to instantiate them too if you instantiate them inside of onCreate where they should be it will work
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); //call superclass's version
setContentView(R.layout.activity_main); //inflate GUI
//get references to the TextViews
//that MainActivity interacts with programmatically
amountDisplayTextView = (TextView) findViewById(R.id.amountDisplayTextView);
percentCustomTextView = (TextView) findViewById(R.id.percentCustomTextView);
tip15TextView = (TextView) findViewById(R.id.tip15TextView);
total15TextView = (TextView) findViewById(R.id.total15TextView);
tipCustomTextView = (TextView) findViewById(R.id.tipCustomTextView);
totalCustomTextView = (TextView) findViewById(R.id.totalCustomTextView);
}
I have 2 editText's and I want to handle both inputs with onTextChanged, can I do this with an array if so how, I dont see how I can do it without using arrays. OK, this is the update on what I have.
public class AlphaActivity extends Activity {
private static final String TO_BOX = "TO_BOX";
private static final String FROM_BOX = "FROM_BOX";
// private String updateGuess;
// private String update_label;
private int guess, theFirst, theLast;
//private int count;
private String update_text;
EditText firstText;
EditText secondText;
TextView updateLabel;
Button tooHighButton;
Button tooLowButton;
Button correctButton;
Button newGameButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alpha);
if(savedInstanceState == null){
// Just started
theFirst = 0;
theLast = 100;
}
else
{
// App is being restored
theFirst = savedInstanceState.getInt(TO_BOX);
theLast = savedInstanceState.getInt(FROM_BOX);
}
//fromBox = (EditText) findViewById(R.id.firstText);
//toBox = (EditText) findViewById(R.id.secondText);
//fromBox.addTextChangedListener(fromBox);
//toBox.addTextChangedListener(toBox);
updateLabel = (TextView)findViewById(R.id.updateText);
firstText = (EditText)findViewById(R.id.firstText);
firstText.addTextChangedListener(fromBoxListener);
secondText = (EditText)findViewById(R.id.secondText);
secondText.addTextChangedListener(fromBoxListener);
tooHighButton = (Button)findViewById(R.id.guiTooHigh);
tooLowButton = (Button)findViewById(R.id.tooLowGui);
correctButton = (Button)findViewById(R.id.correctGui);
setButtonOnClickListeners();
}
private TextWatcher fromBoxListener = new TextWatcher()
{
#Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
try
{
//theFirst = Integer.parseInt(s.toString());
theFirst = Integer.parseInt(firstText.getText().toString());
theLast = Integer.parseInt(secondText.getText().toString());
if (theFirst > theLast)
{
updateLabel.setText("You must flip your integers");
}
else if (theFirst < 0)
{
updateLabel.setText("You cannot enter a negative number!");
}
guess = (theFirst + theLast) / 2;
updateLabel.setText("Did you think of " + guess + " ?");
} catch (NumberFormatException nfe)
{
updateLabel.setText("You must enter an integer! ");
}
//updateLabel();
}
};
private void setButtonOnClickListeners(){
tooHighButton.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
theLast = (guess - 1);
guess = (theFirst + theLast) / 2;
if (theFirst < theLast)
{
secondText.setText("" + theLast);
updateLabel.setText("Did you think of " + guess + " ?");
//count++;
} else if (theFirst > theLast)
{
updateLabel.setText("It appears you changed your number!");
} else
{
updateLabel.setText("Did you think of " + guess + " ?");
}
}
});
tooLowButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
theFirst = (guess + 1);
guess = (theFirst + theLast) / 2;
if (theFirst < theLast)
{
firstText.setText("" + theFirst);
updateLabel.setText("Did you think of " + guess + " ?");
//count++;
} else if (theFirst > theLast)
{
updateLabel.setText("It appears you changed your number!");
} else
{
updateLabel.setText("Did you think of " + guess + " ?");
}
}
});
correctButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0) {
updateLabel.setText("Thank you for playing this game!");
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.alpha, menu);
return true;
}
}
To accomplish what I think you are asking you can do the following,
editText1.addTextChangedListener(fromBoxListener)
editText2.addTextChangedListener(fromBoxListener)
Now, the code in
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
will run when the text in either of them has changed. I'm not sure if this is what you really want since I don't know how your logic works or what you are trying to accomplish in the end.
Also, since you are parsing an Object that could have non-integers, you may want to wrap it in a try/catch or do some type of error-checking
Have you tried moving your code to the afterTextChanged() method of your TextWatcher?
External listeners get updated before the internal Editor of an EditText during the onTextChanged() phase, so your readings for firstText.getText() and secondText.getText() may not return the results you expect because they haven't been internally updated yet.
I am having a problem with setError() on EditText. When an activity is opened, it checks if certain fields are empty and sets error message on them if true. However, the exclamation mark icon is only displayed in case I write some text in field and then delete it. If I lose focus on that field, the icon will disappear again. Both fields Naam and Telefonnumer have this validation.
I use Android 2.2.2 SDK and the application is run on Nexus 7 with latest updates.
I have Util class:
public class Util {
private static String TAG = "Util Class";
public static boolean editTextIsEmpty(EditText edittext) {
if (edittext.getText().toString().trim().length() < 1)
return true;
else
return false;
}
public void editTextListener(final EditText editText) {
editText.addTextChangedListener(new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
if (editTextIsEmpty(editText) && editText.isEnabled())
editText.setError("Nodig");
else
editText.setError(null);
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (editTextIsEmpty(editText) && editText.isEnabled())
editText.setError("Nodig");
else
editText.setError(null);
}
});
}
}
and then I have method validateInput() in my activity:
public class DeliveryActivity extends BaseActivity {
private ImageButton btnSetDate;
private Button btnToSummary;
private Button btnSearchAddress;
private EditText txtPostcode;
private EditText txtHouseNumber;
private EditText txtHouseNumberSuffix;
private EditText txtStreet;
private EditText txtCity;
private EditText txtDeliveryDate;
private EditText txtName;
private EditText txtPhone;
private EditText txtEmail;
private EditText txtRemark;
private TextView lblExtraDeliveryInfo;
private Spinner spinnerDelivery;
private Spinner spinnerDeliveryPeriod;
private Spinner spinnerContact;
private Spinner spinnerDeliveryAddress;
private Spinner spinnerExtraDeliveryInfo;
private RelativeLayout rlDeliveryAddressDetails;
private DevRestHelper additionalDeliveryInfo;
private DevRestHelper searchClientAddress;
private Util util = new Util();
private int year;
private int month;
private int day;
public static final int DIALOG_DATEPICKER = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_delivery);
initControls();
validateInput();
}
private void initControls() {
btnSetDate = (ImageButton) findViewById(R.id.activity_delivery_btnCalendar);
btnToSummary = (Button) findViewById(R.id.activity_delivery_btnSummary);
btnSearchAddress = (Button) findViewById(R.id.activity_delivery_btnSearchAddress);
spinnerDelivery = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryMethod);
spinnerDeliveryPeriod = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryPeriod);
spinnerContact = (Spinner) findViewById(R.id.activity_delivery_spinnerContactperson);
spinnerDeliveryAddress = (Spinner) findViewById(R.id.activity_delivery_spinnerDeliveryAddress);
spinnerExtraDeliveryInfo = (Spinner) findViewById(R.id.activity_delivery_spinnerExtraDeliveryInformation);
txtPostcode = (EditText) findViewById(R.id.activity_delivery_txtPostcode);
txtHouseNumber = (EditText) findViewById(R.id.activity_delivery_txtHousenumber);
txtHouseNumberSuffix = (EditText) findViewById(R.id.activity_delivery_txtHousenumberSuffix);
txtStreet = (EditText) findViewById(R.id.activity_delivery_txtStreet);
txtCity = (EditText) findViewById(R.id.activity_delivery_txtCity);
txtDeliveryDate = (EditText) findViewById(R.id.activity_delivery_txtDeliveryDate);
txtName = (EditText) findViewById(R.id.activity_delivery_txtName);
txtPhone = (EditText) findViewById(R.id.activity_delivery_txtPhone);
txtEmail = (EditText) findViewById(R.id.activity_delivery_txtEmail);
txtRemark = (EditText) findViewById(R.id.activity_delivery_txtRemark);
lblExtraDeliveryInfo = (TextView) findViewById(R.id.activity_delivery_lblExtraDetailInformation);
rlDeliveryAddressDetails = (RelativeLayout) findViewById(R.id.activity_delivery_rlDeliveryAddressDetails);
}
private void validateInput() {
util.editTextListener(txtPostcode);
util.editTextListener(txtHouseNumber);
util.editTextListener(txtDeliveryDate);
}
}
Let me just say that code work on BlueStacks emulator.
There is a known bug with setError on Jelly Bean_MR1 (4.2 and 4.2.1). I am however assuming that the Nexus 7 you are testing with is running one of those versions of Android. See here: http://code.google.com/p/android/issues/detail?id=40417
The error will be shown while you have focus on that EditText field, but when you lose focus, the error icon is not visible to notify the user of the problem.
Before you set Error on any view or edit text, just call the
yourEditText.requestFocus();
yourEditText.setError("Your Error Message");
then set Error. it will solve your problem. Atleast mine did.
try this
new TextWatcher() {
#Override
public void afterTextChanged(Editable s) {
if (editTextIsEmpty(editText) && editText.isEnabled())
editText.setError("Nodig");
else
editText.setError(null);
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// nothing here
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// nothing here
}
}
You can use following code:
May it will be helpful to you:
mPopupInlineErrorBackgroundId = getResourceId(mPopupInlineErrorBackgroundId,
com.android.internal.R.styleable.Theme_errorMessageBackground);
mView.setBackgroundResource(mPopupInlineErrorBackgroundId);
However, you can set a Spanned and a custom error icon using the overloaded setError(CharSequence, Drawable).
You can easily create a Spanned from HTML using fromHtml().
For Example:
yourEditText.setError(Html.fromHtml("<font color='blue'>this is the error</font>"));
This is the only you need to get expected setError behaviour on the TextView
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"