我正在开发一款可在Android设备的/cache
分区上生成交换空间的应用。它已经可以计算交换的最大大小,但是可以输入的最大数量仍然是静态的。
对于EditText
InputFilter
我使用此:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
final EditText mb = (EditText) findViewById(R.id.editText1);
mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", "120")});
...
}
我的无效就是这样:
// 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");
}
如何将120作为MB中long usableSpace
的值?
提前致谢
答案 0 :(得分:1)
如果我理解正确,你想改变TextView的上限,是吗?
mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", Long.toString(usableSpace / 1024 / 1024))});
答案 1 :(得分:0)
谢谢!现在我做对了!完成的,有效的代码是:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
readSpace();
...
final EditText mb = (EditText) findViewById(R.id.editText1);
...
}
和
// 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");
EditText mb = (EditText) findViewById(R.id.editText1);
mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", Long.toString(usableSpace /1024 /1024))});
}