添加项目的ListView android的动态 [英] add items to listview dynamically android
问题描述
如何把在EditText上并点击提交,在窗口应该将它添加到previous活动列表视图项目类型的数据?结果
我需要做的是:
- 创建的EditText和提交按钮
- 在同一活动创建列表视图
- 点击提交按钮应该在列表视图中显示。
您可以创建与持有其提交的数据的公共静态
变量一个新的类,当你pressed按钮。然后覆盖您的previous活动,当您返回到该活动将被称为的 onResume()
事件,并且将数据添加到列表视图。
更新:
公共类GlobalVariable
{
公共静态的ArrayList<对象> exampleList =新的ArrayList<对象>();
}
然后在你的code:
GlobalVariable.exampleList.add(exampleObject);
然后在你的previous活动:
保护无效onResume()
{
//把code添加到这里的ListView
super.onResume();
}
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.
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();
}
这篇关于添加项目的ListView android的动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!