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>