13-5-3 ListView内容的截取全攻略

本文详细介绍了ListView的使用方法,包括如何通过Adapter将数据展示在ListView上,以及如何在用户点击ListView中的项时获取对应内容。通过实例演示了如何监听点击事件并从点击的项中提取信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ListView内容的截取

ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.

其中adapter ArrayAdapter<T>, BaseAdapter, CursorAdapter, HeaderViewListAdapter, ListAdapter, ResourceCursorAdapter, SimpleAdapter, SimpleCursorAdapter, SpinnerAdapter, WrapperListAdapter 

这里我不对adapter进行描述,不管是哪种adapter都是为了将每条信息显示在listview

每条显示的位置都是自己设计好的UI位置,下面我主要讲的是当你单击其中一个item时,如何获取其对应item的内容

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) 

public abstract void  onItemClick (AdapterView<?> parent, View view, int position, long id) 

Parameters

parent     The AdapterView where the click happened. 

view      The view within the AdapterView that was clicked (this will be a view provided by the adapter) 

position    The position of the view in the adapter. 

id          The row id of the item that was clicked.  

TextView temp=(TextView)arg1.findViewById(R.id.wifi_SSID);

ssid=temp.getText().toString();

通过第二个参数,获取当前item对象内容,因为第二个对象是当前事件的对象,可查阅当然目标内容。

 

************************************************************************************************

飞扬小米(记)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值