I want to use the Android Arraylist to put the data in, enter the Edittext window, and show it as a list, but I have no idea.

Asked 2 years ago, Updated 2 years ago, 115 views

Add button on main screen (A)

On the next screen (B)

Enter Email (Edit Text) Enter name (edit text)

Confirmation (Button)

In this screen configuration, press the Email, Name, and OK button in the Edit Text window.

E-mail Name

E-mail Name

It appears on the main screen in format, and when you press the Add button -- the email name -- it adds one by one I'd like to distribute the email and name edit text on the main screen as a list view.

Now, what I want to ask you is that the list view is sprayed by the adapter

It is whether ArrayList can also use an adapter to spray data.

android arraylist edittext

2022-09-21 18:02

1 Answers

Can I print out the email and name in ArrayList as a list view?I understood it as a question of Of course, it's possible. You can inherit and create the Adapter directly or process it using ArrayAdapter.

Please refer to the code below and make it yourself. (You must add an item consisting of the actual "name + email" to the users list)

List<String> users = new ArrayList<>();
users.add("Name1 Email1");
users.add("Name2 Email2");
users.add("Name3 Email3");
users.add("Name4 Email4");
users.add("Name5 Email5");

ArrayAdapter<String> itemsAdapter = 
    new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, users);

ListView listView = (ListView) findViewById(R.id.lvItems);
listView.setAdapter(itemsAdapter);

Or take a look at the example code in the link below.


2022-09-21 18:02

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.