0
public void updateDisplay(View v)
{
    Button button = (Button) findViewById(R.id.button1);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            tempNumber.setText(tempNumber.getText().toString() + ((Button) view).getText());
        }
    });
    tempNumber.setText( tempNumber.getText().toString() + ((Button) v).getText() );


}

my java code

<Button
     android:id="@+id/button1"
     android:layout_width="0dip"
     android:layout_height="wrap_content"
     android:layout_weight="0.1"
     android:background="@drawable/button"
     android:onClick="updateDisplay"
     android:text="1"
     android:layout_marginTop="5dp"
     android:layout_marginBottom="5dp"
     android:textColor="@drawable/button_tx_color"
     android:textSize="15sp" />

my xml code

when i click buttons from 0 to 9 i create numbers. but i also got dot . and minus - signs. how can i check in my textview to allow only one dot in my numbers and allow minus at the top of my number.

Thanks, in advanced...

coreprojectz
  • 134
  • 1
  • 3
  • 12

1 Answers1

0

I don't think you can achieve this via layout attribute alone.

Hoever you can base your validation on this answer, which is based on that older one. Basically you implement a TextWatcher for your EditText, which has its method invoked on every text change.

From then on you need only proper regex validation and something like that should do:

String pattern = "^[0-9]+\.[0-9]*$";
String yourEditTextValue;
if (yourEditTextValue.matches(pattern)) {
} else {
   // set edit text valeu to empty string, show erorr
}
Community
  • 1
  • 1
Boris Strandjev
  • 45,192
  • 14
  • 103
  • 128