javaandroidandroid-edittextdiskspaceinput-filter

Use value from void in onCreate inputfilter


I'm working on an app which generates swap space on the /cache partition of Android devices. It can already calculate the maximum size of the swap, but the maximum amount one can enter is still static.

For the EditText InputFilter I use this:

@Override
protected void onCreate(Bundle savedInstanceState) {  
    ... 
    final EditText mb = (EditText) findViewById(R.id.editText1);
    mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", "120")});
    ...
}

And my void is this:

// Check Disk Space and display
void readSpace(){
    execCommandLine("mount -o rw,remount /cache");
    File spacechecker = new File("/cache");
    long totalSpace = spacechecker.getTotalSpace();
    long usableSpace = spacechecker.getUsableSpace();

    TextView tsp = (TextView) findViewById(R.id.AmmountTotal);
    tsp.setText(totalSpace /1024 /1024 + " MB");

    TextView usp = (TextView) findViewById(R.id.AmmountAvailable);
    usp.setText(usableSpace /1024 /1024 + " MB");

    TextView rsp = (TextView) findViewById(R.id.AmmountRecommended);
    rsp.setText(usableSpace /1024 /1024 -20 + " MB");
}

How can I get the 120 to be the value of long usableSpace in MB?

Thanks in advance


Solution

  • If I'm understanding this correctly, you want to change the upper limit of your TextView, yes?

      mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", Long.toString(usableSpace / 1024 / 1024))});