Java Android studio将int设置为从一个活动到另一个活动的文本视图
我想在TextView中设置从一个活动到另一个活动的数据 这是我的主要活动,我想当用户成功登录时在TextView中显示他的ID。这是我要发送“IdAccount”的变量。这是另一个活动“成功登录”。我想在这个textView“textViewId”中设置它 这是我的登录名。\u successfully.xmlJava Android studio将int设置为从一个活动到另一个活动的文本视图,java,android,android-studio,Java,Android,Android Studio,我想在TextView中设置从一个活动到另一个活动的数据 这是我的主要活动,我想当用户成功登录时在TextView中显示他的ID。这是我要发送“IdAccount”的变量。这是另一个活动“成功登录”。我想在这个textView“textViewId”中设置它 这是我的登录名。\u successfully.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:an
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="@drawable/gradient"
tools:context=".MainActivity">
<TextView
android:id="@+id/textViewId"
android:layout_width="329dp"
android:layout_height="41dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="25dp"
android:layout_marginBottom="663dp"
android:layout_weight="1"
android:text="Login successfully" />
<TextView
android:id="@+id/textView2"
android:layout_width="329dp"
android:layout_height="41dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="80dp"
android:layout_marginBottom="564dp"
android:layout_weight="1"
android:text="Login successfully" />
</RelativeLayout>
您知道如何发送此ID吗?我建议您编写另一个活动类,而不是setContentView
Intent intent = new Intent(MainActivity.this,YourNewActivity.class);
intent.putExtra("IdAccount", IdAccount);
startActivity(intent);
在创建新活动时,您可以使用
getIntent().getIntExtra("IdAccount",0);
之后,您可以使用
findViewById(yourTextViewId)
并设置文本给我这个错误:在第一行中找不到适合Intent(,Class)的构造函数try:Intent Intent=newintent(MainActivity.this,YourNewActivity.Class);
getIntent().getIntExtra("IdAccount",0);