问题
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:
- Creating EditText and submit button
- Creating listview in same Activity
- 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