简体   繁体   中英

add items to listview dynamically android

How to take data that was typed in EditText and by clicking "submit" in that window should add it to previous activity listview items?
What I need to do is:

  1. Creating EditText and submit button
  2. Creating listview in same Activity
  3. By clicking submit button it should display it in listview.

You could create a new class with a public static variable that holds the data which was submitted when you pressed the button. Then override the onResume() event of your previous activity, which will be called when you return to the activity, and add the data into the listview.

UPDATE:

public class GlobalVariable
{
    public static ArrayList<Object> exampleList = new ArrayList<Object>();
}

Then in your code:

GlobalVariable.exampleList.add(exampleObject);

Then in your previous activity:

protected void onResume()
{
    // Put code to add to listview here
    super.onResume();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM