0

我正在开发一个在/cacheAndroid 设备的分区上生成交换空间的应用程序。它已经可以计算出交换的最大大小,但可以输入的最大数量仍然是静态的。

对于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 成为long usableSpaceMB 的值?

提前致谢

4

2 回答 2

1

如果我理解正确,您想更改 TextView 的上限,是吗?

  mb.setFilters(new InputFilter[]{ new InputFilterMinMax("1", Long.toString(usableSpace / 1024 / 1024))});
于 2013-04-10T17:15:53.863 回答
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))});

}
于 2013-04-10T17:41:12.573 回答