这个很简单 就是为了说明别忘了adapter.notifyDataSetChanged();
唤醒一下,其实这个唤醒也就是在buutton下用 或者在别的控件下调用 如果是在getView下就不必了
ublic class DynamicListItems extends ListActivity {
private static final String ITEM_KEY = "key";
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private SimpleAdapter adapter;
private EditText newValue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_list);
newValue = (EditText) findViewById(R.id.new_value_field);
setListAdapter(new SimpleAdapter(this, list, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value }));
((ImageButton) findViewById(R.id.button)).setOnClickListener(getBtnClickListener());
}
private OnClickListener getBtnClickListener() {
return new OnClickListener() {
public void onClick(View view) {
try {
HashMap<String, String> item = new HashMap<String, String>();
item.put(ITEM_KEY, newValue.getText().toString());
list.add(item);
adapter.notifyDataSetChanged();
} catch (NullPointerException e) {
Log.i("[Dynamic Items]", "Tried to add null value");
}
}
};
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
android:cacheColorHint="#00000000">
</ListView>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6px"
android:layout_marginBottom="8px"
android:layout_marginLeft="8px"
android:layout_marginRight="8px"
android:background="#00000000">
<ImageButton
android:id="@+id/button"
android:layout_width="100px"
android:layout_height="100px"
android:src="@android:drawable/ic_menu_add" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="230px"
android:layout_height="wrap_content"
android:layout_marginTop="8px"
android:layout_marginBottom="8px"
android:layout_marginLeft="0px"
android:layout_marginRight="28px"
android:background="#cccccc00" >
<EditText android:id="@+id/new_value_field"
android:textColor="#020905"
android:textSize="18sp"
android:layout_marginTop="6px"
android:layout_marginBottom="8px"
android:layout_marginLeft="12px"
android:layout_marginRight="12px"
android:layout_width="210px"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
row
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<TextView
android:id="@+id/list_value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
分享到:
相关推荐
LsitView树形结构,电话簿等一系列的应用基本代码
自定义listview,实现listview的下拉刷新和加载更多功能
对于Listview未满一屏添加footerView 满了一屏幕将View固定在屏幕下方的解决方案
如何使用,参考:http://www.see-source.com/blog/300000022/670.htmlgithub地址:https://github.com/hanks-zyh/SlideLayout
ListView item的渐入效果,比较实用。
实现弹性ListView 实现节点 添加ScrollBar
Android里ListView里面添加CheckBox实现多选,用上ViewHolder和ConvertView
RecycleView ,LsitView,GridView,瀑布流
好了,大家先看一下效果图,毕竟是看脸的世界。 好了,我要先讲一下思路,一次编辑很难完善,有什么问题我后来还会补上,欢迎各位大神拍砖: 1、首先先说一下item:item用的LinearLayout布局,删除、编辑分别是写...
Android 解决在ListView历史复用中Edittext数据显示混乱
c#读取txt,xml,excel中的数据,绑定到lsitview ,dataview
子LsitView的出现是由点击事件触发的,故存在问题:父ListView某一Item点击出现了子ListView,然后往下滑动时,布局复用那个Item时,也把子ListView出现(希望只有在点击时才出现子ListView) ~~以上两个问题都解决...
简单的实现了水平的lsitView,初学者可以看看,大神们可以提点建议
C#编程 本代码利用文件流技术实现对于listBox和listView与文本文件的传值,熟悉此代码可充分掌握文件流技术和listBox和lsitView的使用
RT,顶部下拉刷新 + 底部点击更多 的LSITVIEW,代码更清晰,注释更详尽,修复网上部分demo存在的bug,让尼一看就懂,一学就会,一拿就用
android自定义 view中的菜单initData(); initView(); mlistView.setAdapter(new ... mlistView = (ListView) findViewById(R.id.id_lsitview); mArcMenu=(ArcMenu)findViewById(R.id.id_menu); } }
将代码直接嵌入自己的开发中,调用方法即可,使用方法见下载文件中的注意事项,该资源解决大部分人的listview加载网络图片的头痛问题,但要求比较高的程序员,可能不太完美,仁者见仁,智者见智吧
Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
模仿淘宝分类,效果图http://blog.csdn.net/hu5080126/article/details/48049847 如果有更好的建议,请务必提出,一起学习
简单的小例子listview的demo,用于显示listview的背景颜色,漂亮的listview