Java 在活动之间传递textview值

Java 在活动之间传递textview值,java,android,Java,Android,我有个问题。 我有两个文本视图,它们在单击按钮时会增加,但我不知道如何将文本视图的值传递给下一个同样有两个文本视图的活动。就像在第一个活动中将值增加1一样,在同一文本视图的第二个活动中,将出现值1,依此类推。。。 我正在尝试将textview值传递给下一个活动,我尝试了一些使用putextra方法的方法,但没有成功。 这是密码 Button btnIncrement; private CheckBox i1, i2, i3; public Button bckbutton; TextVie

我有个问题。 我有两个文本视图,它们在单击按钮时会增加,但我不知道如何将文本视图的值传递给下一个同样有两个文本视图的活动。就像在第一个活动中将值增加1一样,在同一文本视图的第二个活动中,将出现值1,依此类推。。。 我正在尝试将textview值传递给下一个活动,我尝试了一些使用putextra方法的方法,但没有成功。 这是密码

  Button btnIncrement;
private CheckBox i1, i2, i3;
public Button bckbutton;

TextView rspCorecte;
TextView rspGresite;

int counterCorecte=0;
int counterGresite=0;




private void initialStates(Intent intent) {
    i1=findViewById(R.id.q1_1);
    i2=findViewById(R.id.q1_2);
    i3=findViewById(R.id.q1_3);
}
然后

   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.intrebarea_1);
    initialStates(getIntent());

    final AlertDialog.Builder alert2=new AlertDialog.Builder(Intrebarea1.this);
    LayoutInflater factry=LayoutInflater.from(Intrebarea1.this);
    final View view2=factry.inflate(R.layout.raspuns_corect, null);
    alert2.setView(view2);
    alert2.setPositiveButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
             finish();
        }
    });


    final AlertDialog.Builder alertadd = new AlertDialog.Builder(Intrebarea1.this);
    LayoutInflater factory = LayoutInflater.from(Intrebarea1.this);
    final View view = factory.inflate(R.layout.raspuns1, null);
    alertadd.setView(view);
    alertadd.setPositiveButton("", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dlg, int sumthin) {
            startActivity(new  Intent(Intrebarea1.this,Intrebarea2.class));
            finish();
        }
    });

    // SEMNUL INTREBARII
    //reference of button added in the main layout
    final Button raspuns = findViewById(R.id.arataraspuns);
    //setting click event listener to button
    raspuns.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(Intrebarea1.this);
            View view = LayoutInflater.from(Intrebarea1.this).inflate(R.layout.raspuns1, null);

            builder.setView(view);
            builder.show();

        }
    });


    bckbutton=(Button) findViewById(R.id.backbutton);
    bckbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
    onBackPressed();
}
}))

}

有人能告诉我如何将textview值传递给下一个活动吗? 提前谢谢

   Intent intent = new Intent(getBaseContext(), MainActivity.class);
   // change the MainActivity if you want to pass the value to another activity
   intent.putExtra("text", text);
   startActivity(intent);
在下一个要获取值的活动中:

   Intent intent = getIntent();


   String text = intent().getStringExtra("text");

谢谢,但我没弄明白。。你能编辑我的代码吗?:)“我尝试了一些使用额外方法的方法,但没有效果。”我在你的代码中没有看到类似的内容。如果您对使用putExtra()的代码有问题,请显示该代码,而不是其他不相关的内容。我尝试过,但我将代码保持在我尝试之前的状态。。我还是用putExtra()删除了代码…“我还是用putExtra()删除了代码”为什么?现在我们不知道它出了什么问题。
   Intent intent = getIntent();


   String text = intent().getStringExtra("text");