Bom dia senhores, estou com dificuldades em colocar uma mascara monetária em um Edit Text, verifiquei diversos fóruns e tutoriais porém nenhum método funcionou. O meu projeto é fazer basicamente o cliente colocar o valor do produto no Edit Text, isso já está funcionando, porém eu gostaria de colocar uma máscara, poderiam me ajudar ?
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();
}
}