只想使用一行代码来执行此操作。目前,代码如下所示,并且可以正常工作:
TextView powerLvl = findViewById(R.id.powerLevel);
int limit = Integer.parseInt(powerLvl.getText().toString());
这很好用。但是,我只想一行。类似于以下内容:
int limit = Integer.parseInt(findViewById(R.id.powerLevel).toString());
当应用程序尝试执行此行代码时,它停止工作。不知道发生了什么。
难道不是应该获取整数,将其放入字符串中以便可以对其进行解析并具有可用于限制变量的int值吗?