【发布时间】:2015-12-08 03:17:22
【问题描述】:
编程勇士们好,请帮我解决这个简单的问题,我是 android 新手。如何将 TextView 值转换为整数。请看我附上的代码,谢谢。
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, "你的分数是:" + total, Toast.LENGTH_LONG).show();给我0分。
【问题讨论】:
-
看我的回答here。和你的问题一样。
标签: javascript android android-intent