listview的基本使用
来源:互联网 发布:java 2进制实战 编辑:程序博客网 时间:2024/05/22 11:42
一、listview是一个非常复杂的控件, 这里先说说listview 数据的加载,已经listview点击item事件。 怎样删除整行。
二、a、要想在listview里面加多个控件,我们需要一个视图, 视图里面包括要在listview里面呈现的控件
b、有了视图以后,就要加载数据,这是使用了适配器。 我个人喜欢自定义适配器
c、listview 点击item事件, listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
//处理代码
}}
三、注意: 在listview里面会出现,点击item无效。 这里有很多方法解决。 其一:在listview需要解析的视图里面 加上 android:descendantFocusability= "blocksDescendants"
看图:
a、加载视图 xml代码如下:
<?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="fill_parent" android:orientation="horizontal" android:descendantFocusability= "blocksDescendants" > <ImageView android:id="@+id/ivicon" android:layout_width="40dip" android:layout_height="wrap_content" /><LinearLayout android:layout_width="220dip" android:layout_height="90dip" android:orientation="vertical" > <TextView android:id="@+id/tv1" android:layout_width="220dip" android:layout_height="40dip" /> <TextView android:id="@+id/tv2" android:layout_width="220dip" android:layout_height="50dip" /> </LinearLayout><Button android:id="@+id/btndel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="删除" /></LinearLayout>
java核心代码如下:
LayoutInflater inflater = getLayoutInflater();View row = inflater.inflate(R.layout.rowlayout, null);// 从创建的行视图当中获取要填充数据的两个控件,ImageView和TextViewImageView iv = (ImageView) row.findViewById(R.id.ivicon);tv1 = (TextView) row.findViewById(R.id.tv1);tv2 = (TextView) row.findViewById(R.id.tv2);
listview点击事件:
list1.setOnItemClickListener(new OnItemClickListener() {public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {Log.e("-----------onItemClick", "positoin" + arg2 + ":arg1:"+ arg1);tv1 = (TextView) arg1.findViewById(R.id.tv1);Log.e("-----------", tv1.getText().toString());Toast.makeText(Zt_03_listview2Activity.this,tv1.getText().toString(), Toast.LENGTH_SHORT).show();}});最后: 有写得不对的地方请大家指正, 一起探讨。
listview的基本使用完整代码: http://115.com/file/be0ukjn0#zt_03_listview2.rar
- Listview 的基本使用
- listview的基本使用
- listview的基本使用,listview的优化
- ListView的基本使用技巧
- 【Android 开发教程】ListView的基本使用
- (Android review)ListView的基本使用
- ListView的基本使用与优化
- android学习之ListView的基本使用
- ListView的基本使用与优化
- Android基本控件ListView的使用总结
- [android]_[ListView的基本使用]
- ListView的基本使用及其优化
- ListView之BaseAdapter的基本使用
- ListView 基本使用
- ListView基本使用
- ListView基本使用
- ListView基本使用
- ListView基本使用
- C#异步编程
- 安卓开发调试工具DDMS使用介绍
- 授权监控十条自查
- 求一个字符串中连续出现次数最多的字串
- python 操作IE
- listview的基本使用
- HDU1002
- redhat Linux系统 6.1版本 安装系统桌面
- SHELL 编程入门与提高(四)SHELL脚本中函数的应用
- HDU1004
- Oracle 建表常用数据类型详解
- 机器学习论文与书籍推荐
- HDU1228
- HDU1229