展会信息港展会大全

Android控件 ListView 的用法
来源:互联网   发布日期:2015-11-26 11:16:33   浏览:2494次  

导读:SimpleAdapter simpleadapter = new SimpleAdapter(this, bookList, R.layout.mylistitem,new String[]{bookName,path}, new int[]{R.id.bookName,R.id.bookPath}); listView.setAd......

SimpleAdapter simpleadapter = new SimpleAdapter(this, bookList, R.layout.mylistitem,new String[]{"bookName","path"}, new int[]{R.id.bookName,R.id.bookPath});

listView.setAdapter(simpleadapter);

listView.setOnItemClickListener(new OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent,

View view,

int position,

long id) {

// TODO Auto-generated method stub

Intent intent = new Intent();

rowItem = bookList.get(position);

String string = rowItem.get("path").toString();

intent.putExtra("book",string);

intent.setClass(ReaderActivity.this,NovelPage.class);

startActivity(intent);

}

在这里使用ListView的话,我们需要有一个Adapter来配置 ,下面是ListView的数据属性,这一点和Flex里面的很像。然后通过setOnItemClickListener来设置点击事件的监听函数。

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

这里的第三个参数position就是点击的位置。

下面是Item 的配置 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="wrap_content"

android:background="@drawable/listbk"

android:orientation="horizontal" >

<ImageView

android:id="@+id/imageView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:paddingBottom="10dip"

android:paddingLeft="10dip"

android:paddingRight="10dip"

android:paddingTop="10dip"

android:src="@drawable/unknown_cover" />

<LinearLayout

android:id="@+id/linearLayout1"

android:layout_width="wrap_content"

android:layout_height="match_parent" android:orientation="vertical">

<TextView

android:id="@+id/bookName"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:paddingBottom="10dip"

android:paddingLeft="10dip"

android:paddingRight="10dip"

android:paddingTop="10dip"

android:text="TextView" />

<TextView

android:id="@+id/bookPath"

android:layout_width="210dp"

android:layout_height="wrap_content"

android:layout_weight="0.36"

android:paddingBottom="10dip"

android:paddingLeft="10dip"

android:paddingRight="10dip"

android:paddingTop="10dip"

android:text="TextView" />

</LinearLayout>

</LinearLayout>

赞助本站

人工智能实验室

相关热词: 控件 ListView

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港