好日子编程勇士,请帮我解决这个简单的问题,我是新来的android。如何将TextView值转换为Integer。请看我附上的代码,谢谢。如何将TextView值转换为Integer
public class appleTrivia extends AppCompatActivity {
public int total = 0;
public int score = 40;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apple_trivia);
TextView scoreLabel = (TextView) findViewById(R.id.labelScore);
scoreLabel.setText("Score: " + score);
scoreLabel.setText("Score: " + getIntent().getExtras().getInt("points", 0));
try {
total = Integer.parseInt("score: " + scoreLabel);
}
catch (NumberFormatException nfe)
{
}
}
public void onClickProceed (View view) {
Intent intent = new Intent(this, cherry.class);
startActivity(intent);
Toast.makeText(appleTrivia.this, "Your score is:" + total, Toast.LENGTH_LONG).show();
}
}
我需要将scoreLabel值转换为整数,所以我可以将它添加到另一个分数,谢谢。 PS。 Toast.makeText(appleTrivia.this,“Your score is:”+ total,Toast.LENGTH_LONG).show();给我0分。
看我的答案[这里](http://stackoverflow.com/a/34481681/2649104)。和你的问题一样。 –