I have a Recyclerview
wich is populating the data with a resource file that contains an Arraylist
.
I have a second activity which contains an Edidtext
and a Button
that inserts values to another Arraylist
set in this second activity.
What I need is to use the Arraylist
on the second activity to populate the Recyclerview
instead using the data of the resource file.
I've tried to pass the Arraylist
of one activity to another using Intent
but didn't get succeed.
ArrayList in the ViewHolder
public ListAdapter(Context context) {
mContext = context;
final String[] countryNames = context.getResources().getStringArray(R.array.country_names);
mItems = new ArrayList<>();
for (int i = 0; i < countryNames.length; i++) {
mItems.add(new LineItem(countryNames[i]));
}
}
Arraylist in the second activity that I want to use as data
public class DisplayDescActivity extends AppCompatActivity {
private EditText descItem;
public static ArrayList<String> descList = new ArrayList<String>();
...
}
Is there a way to do that?
Intent
code tried:
DisplayDescActivity code:
On theprotected void onCreate(Bundle savedInstanceState)
i've used:Intent intent1 = new Intent(this, ListAdapter.class); intent1.putStringArrayListExtra("list", descLista); startActivity(intent1);
ListAdapter code:
I've tried to use the following codefinal ArrayList<String> resultArray = getIntent().getStringArrayListExtra("list");
But the massage Cannot resolve method'getIntent()'
appears.