Java 使用Intent传递整数在Android中不起作用
我有一个打开新活动的意图设置,我想传递一个整数值。活动的开始起作用,但一旦我使用代码传递价值,应用程序就会崩溃 这是我的主要活动代码-Java 使用Intent传递整数在Android中不起作用,java,android,android-intent,Java,Android,Android Intent,我有一个打开新活动的意图设置,我想传递一个整数值。活动的开始起作用,但一旦我使用代码传递价值,应用程序就会崩溃 这是我的主要活动代码- public void onFinish() { tap1.setClickable(false); Intent i = new Intent( Single.this, FinalScore.class); i.putExtra("kee1", count); startActivity(i); 使用以下代码获取值: protected v
public void onFinish() {
tap1.setClickable(false);
Intent i = new Intent( Single.this, FinalScore.class);
i.putExtra("kee1", count);
startActivity(i);
使用以下代码获取值:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_final_score);
TextView tx = (TextView) findViewById(R.id.textView3);
tx.setText(getIntent().getExtras().getInt("kee1"));
}
您需要将
int
值转换为String
,以便设置为TextView
:
您可以使用以下代码:
tx.setText(""+getIntent().getExtras().getInt("kee1"));
将“”
添加到第一个值,然后为您执行此操作
或者,您可以使用以下代码来强制转换:
String value = String.valueOf(getIntent().getExtras().getInt("kee1"));
tx.setText(value);
您可以使用
Integer.toString()
也是@Duncan在评论中提到的。您需要将int
值转换为String
,才能设置为TextView
:
您可以使用以下代码:
tx.setText(""+getIntent().getExtras().getInt("kee1"));
将“”
添加到第一个值,然后为您执行此操作
或者,您可以使用以下代码来强制转换:
String value = String.valueOf(getIntent().getExtras().getInt("kee1"));
tx.setText(value);
您可以使用
Integer.toString()
也是@Duncan在评论中提到的。您需要将int
值转换为String
,才能设置为TextView
:
您可以使用以下代码:
tx.setText(""+getIntent().getExtras().getInt("kee1"));
将“”
添加到第一个值,然后为您执行此操作
或者,您可以使用以下代码来强制转换:
String value = String.valueOf(getIntent().getExtras().getInt("kee1"));
tx.setText(value);
您可以使用
Integer.toString()
也是@Duncan在评论中提到的。您需要将int
值转换为String
,才能设置为TextView
:
您可以使用以下代码:
tx.setText(""+getIntent().getExtras().getInt("kee1"));
将“”
添加到第一个值,然后为您执行此操作
或者,您可以使用以下代码来强制转换:
String value = String.valueOf(getIntent().getExtras().getInt("kee1"));
tx.setText(value);
您可以使用Integer.toString()代码>也是@Duncan在评论中提到的。或Integer。toString(…)
可能更好。我讨厌在代码中看到”+…
,或者整数。toString(…)
可能更好。我讨厌在代码中看到”+…
,或者整数。toString(…)
可能更好。我讨厌在代码中看到”+…
,或者整数。toString(…)
可能更好。我讨厌在代码中看到“”+…
。