add items to listview dynamically android

六眼飞鱼酱① 提交于 2019-12-11 02:13:23

问题


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.

回答1:


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();
}


来源:https://stackoverflow.com/questions/6826148/add-items-to-listview-dynamically-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!