常见适配器的用法(在listview中 ,把三个edittext内容放在简单适配器中)
来源:互联网 发布:mac怎么关闭系统弹出 编辑:程序博客网 时间:2024/05/21 12:50
List作为数据源,填充SimpleAdapter
(1)在listview中 ,把三个edittext内容放在简单适配器中
先定义布局文件avtivity_main.xml
<?xml version ="1.0" encoding ="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/listView" /> </LinearLayout>
(2)在定义布局文件item.xml,设置edittext 的布局
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="120dip" android:layout_height="match_parent" android:id="@+id/name" /> <TextView android:layout_width="150dip" android:layout_height="match_parent" android:id="@+id/phone" /> <TextView android:layout_width="fill_parent" android:layout_height="match_parent" android:id="@+id/amount" /> </LinearLayout>
(3)下面的方式就是把item.xml中的三个edittext,放在listview中,需要借助于SimpleAdapter,和list,
1)首相定义listview,设置监听;
2)接下来定义list,用put方法往list中写入数据;
3)最后定义适配器,需要找到edittext对应的id,布局里对应的内容放在list中再把它放在适配器里,
下面是在MainActivity.java代码实现过程
import java.util.ArrayList;import java.util.HashMap; import android.R.string;import android.os.Bundle;import android.app.Activity;import android.view.Menu;import android.widget.ListView;import android.widget.SimpleAdapter; public class MainActivity extends Activity{ private ListView listview; protected voidonCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listview=(ListView)findViewById(R.id.listView); ArrayList<HashMap<String,String>> aList= new ArrayList<HashMap<String,String>>(); for (int i = 0; i < 30; i++) { HashMap<String,String> map = newHashMap<String, String>(); map.put("name","1"); map.put("phone","2"); map.put("amount","3"); aList.add(map); } SimpleAdapter saAdapter= newSimpleAdapter(this, aList, R.layout.item, new String []{ "name","phone","amount"}, new int []{R.id.name,R.id.phone,R.id.amount} ); listview.setAdapter(saAdapter); }}
按照这样的步骤,一个简单的适配器就做好了!
- 常见适配器的用法(在listview中 ,把三个edittext内容放在简单适配器中)
- Android - ListView自定义适配器Adapter中获得EditText的值
- 在edittext中输入内容,动态匹配更新 listview的数据(EditText中边输入,listView边更新)
- ListView的适配器中viewHolder
- Android 中怎么把edittext光标放在文字下面
- 在Android中自定义适配器
- 把sql字符串中选择的内容显示在ListView
- 在ListView中嵌套EditText,EditText内容过多需要滚动的问题
- 在ListView中修改EditText的值
- 在ListView中修改EditText的值
- ListView中适配器的配置使用
- listView适配器中getView的问题
- Android中Listview适配器的优化写法
- android常见三个适配器
- tabHost研究二 ,android应用中,大部分的软件都会采用把按钮放在底部显示(tabHost)。利用三个Radiobutton嵌套在RadioGroup 。
- 适配器模式在android中使用
- android在适配器中局部刷新界面
- 在适配器中实现接口SectionIndexer
- 第13 周项目用递归法求n!
- 进程
- HDOJ 1212 Big Number
- 关于集合框架类的学习笔记
- 马老总的PK理论
- 常见适配器的用法(在listview中 ,把三个edittext内容放在简单适配器中)
- 另一个求阶乘
- 【大数】递归写大数感觉良好
- 3.深入PHP中的引用
- python调用os.system执行系统命令,中文输出显示乱码
- 输出满足n=a!+b!+c!的所有三位数
- JAVA构造函数运行解析
- 2013-11-19日志
- android 相对布局