簡體   English   中英

如何將MainActivity中的值添加到SecondActivity中的列表中

[英]How to add values from MainActivity to list in SecondActivity

我在將值添加到SecondActivity中的列表時遇到問題。 在MainActivity中,我在EditText框中設置文本並發送給第二類。 第一次添加值,但是當我回到上一個活動,又一次設置文本並發送時,列表中的值將被替換,而不是添加。 有人知道這個問題的根源是什么?

在第一個活動中嘗試以下方法:

String[] array = {"Hi", "there", "yeah"};
    Intent goIntent = new Intent(this, NewAppActivity.class);
    /*
    * put extra with "array" as a key and the String[] with your values as the value to pass
    * */
    goIntent.putExtra("array", array);
    startActivity(goIntent);

在第二個活動中:

Bundle extras = getIntent().getExtras();
    if (extras != null) {
        String[] array = extras.getStringArray("array");
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM