添加项目的ListView android的动态 [英] add items to listview dynamically android

查看:111
本文介绍了添加项目的ListView android的动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何把在EditText上并点击提交,在窗口应该将它添加到previous活动列表视图项目类型的数据?结果
我需要做的是:


  1. 创建的EditText和提交按钮

  2. 在同一活动创建列表视图

  3. 点击提交按钮应该在列表视图中显示。


解决方案

您可以创建与持有其提交的数据的公共静态变量一个新的类,当你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:

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

这篇关于添加项目的ListView android的动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆