2
Good morning gentlemen, I’m having trouble putting a monetary mask on an Edit Text, I checked several forums and tutorials but no method worked. My project is to basically make the customer put the value of the product in Edit Text, this is already working, however I would like to put a mask, could help me ?
public class Tecladonumerico extends AppCompatActivity {
public Button botao1;
public Button botao2;
public Button botao3;
public Button botao4;
public Button botao5;
public Button botao6;
public Button botao7;
public Button botao8;
public Button botao9;
public Button botao0;
public Button botaoX;
public Button botaoC;
public Button botaoA;
public EditText valor;
Boolean bool = false;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate( savedInstanceState );
setContentView( R.layout.layoutcores );
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( dm );
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setGravity( Gravity.TOP );
getWindow().setLayout( (int) (width * .8), (int) (height * .8) );
//AQUI ESTÁ A VÁRIAVEL QUE CHAMA OS DADOS DO EDIT TEXT
valor = (EditText) findViewById( R.id.calcula);
botao1 = (Button) findViewById(R.id.button1);
botao2 = (Button) findViewById(R.id.button2);
botao3 = (Button) findViewById(R.id.button3);
botao4 = (Button) findViewById(R.id.button4);
botao5 = (Button) findViewById(R.id.button5);
botao6 = (Button) findViewById(R.id.button6);
botao7 = (Button) findViewById(R.id.button7);
botao8 = (Button) findViewById(R.id.button8);
botao9 = (Button) findViewById(R.id.button9);
botao0 = (Button) findViewById(R.id.button0);
botaoA= (Button) findViewById(R.id.buttona);
botaoX = (Button) findViewById(R.id.buttonx);
botaoC = (Button) findViewById(R.id.buttonc);
}
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent();
setResult(RESULT_CANCELED, intent);
finish();
}
public void Botao1(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "1");
}
}
public void Botao2(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "2");
}
}
public void Botao3(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "3");
}
}
public void Botao4(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "4");
}
}
public void Botao5(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "5");
}
}
public void Botao6(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "6");
}
}
public void Botao7(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "7");
}
}
public void Botao8(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "8");
}
}
public void Botao9(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "9");
}
}
public void Botao0(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText(str + "0");
}
}
public void BotaoC(View view){
if (bool == false){
String str = valor.getText().toString();
valor.setText("");
}
}
public void BotaoA(View view){
String str = valor.getText().toString();
Intent intent = new Intent();
intent.putExtra("KEY", str);
this.setResult(RESULT_OK, intent);
this.finish();
}
public void botaoX(View v){
this.finish();
}
}
What would this value.setText(str + "1")... did not understand this. I have a mask here that leaves the format of the Edittext numbers according to the location of the person. example 1000 in Br is 1,000.00 in USA 1,000.00 in some European countries 1 000.00
– Murillo Comino
this (str+"1") allows me to put the number "1" as many times as I want in the value field, for example: if I fill in once the value of str will be "1", then I will fill in again with the same value and it will become "11" and so on
– Dev