1
I’m making an application that takes the data entered in a EditText
and makes a certain calculation.
The problem is that I need the field to go from 1 to 100%, but the "Mask" I’m using is too simple for that, so it only does the limitation but it goes from 0 to 999 and that’s not what I want.
Nor can I place the % symbol at the end of that field.
Follows the code:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import com.github.rtoshiro.util.format.MaskFormatter;
import com.github.rtoshiro.util.format.SimpleMaskFormatter;
import com.github.rtoshiro.util.format.pattern.MaskPattern;
import com.github.rtoshiro.util.format.text.MaskTextWatcher;
public class ActivityForm extends AppCompatActivity {
private EditText percentual;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_form);
percentual = (EditText) findViewById(R.id.percentual_Id);
SimpleMaskFormatter simpleMaskPercentual = new SimpleMaskFormatter( " NNN% " );
MaskTextWatcher maskPercentual = new MaskTextWatcher(percentual, simpleMaskPercentual);
percentual.addTextChangedListener( maskPercentual );
}
}
You want it to go from 1% to 100% or from 0% to 100%?
– Victor Stafusa
from 1% to 100% because the customer must specify how much he wants to invest
– Arthur Santos
Okay, I edited my answer. Tell me if it fits.
– Victor Stafusa
I’m new to this part of masks and I’m a little confused here... I downloaded the dependency directly from Github so I just copied and pasted in build.gradle... this code you posted, should be created in a new file?
– Arthur Santos
Two files, one
PercentTextWatcher.java
and aActivityForm.java
. Both in the same folder where you already have theActivityForm.java
. If you can’t do it, let me know that I can easily put it in the same file.– Victor Stafusa
Would it be too much to ask you to do that? I tried to create the file here and returned it: Unable to parse template "Class" Error message: This template Did not Produce a Java class or an interface
– Arthur Santos
Okay, I edited the answer.
– Victor Stafusa
Let’s go continue this discussion in chat.
– Arthur Santos