【Android基本控制項】ListView 的用法

來源:互聯網
上載者:User
 SimpleAdapter simpleadapter = new SimpleAdapter(this, bookList, R.layout.mylistitem,new String[]{"bookName","path"}, new int[]{R.id.bookName,R.id.bookPath});<br /> listView.setAdapter(simpleadapter);<br /> listView.setOnItemClickListener(new OnItemClickListener() {</p><p>@Override<br />public void onItemClick(AdapterView<?> parent,<br />View view,<br />int position,<br />long id) {<br />// TODO Auto-generated method stub</p><p> Intent intent = new Intent();<br /> rowItem = bookList.get(position);<br /> String string = rowItem.get("path").toString();<br /> intent.putExtra("book",string);</p><p> intent.setClass(ReaderActivity.this,NovelPage.class);<br /> startActivity(intent);<br />}

在這裡使用ListView的話,我們需要有一個Adapter來配置 ,下面是ListView的資料屬性,這一點和Flex裡面的很像。然後通過setOnItemClickListener來設定點擊事件的監聽函數。

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

這裡的第三個參數position就是點擊的位置。

下面是Item 的配置 xml</p><p><?xml version="1.0" encoding="utf-8"?><br /><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"<br /> android:layout_width="fill_parent"<br /> android:layout_height="wrap_content"<br /> android:background="@drawable/listbk"<br /> android:orientation="horizontal" ></p><p> <ImageView<br /> android:id="@+id/imageView1"<br /> android:layout_width="wrap_content"<br /> android:layout_height="wrap_content"<br /> android:paddingBottom="10dip"<br /> android:paddingLeft="10dip"<br /> android:paddingRight="10dip"<br /> android:paddingTop="10dip"<br /> android:src="@drawable/unknown_cover" /></p><p> <LinearLayout<br /> android:id="@+id/linearLayout1"<br /> android:layout_width="wrap_content"<br /> android:layout_height="match_parent" android:orientation="vertical"></p><p> <TextView<br /> android:id="@+id/bookName"<br /> android:layout_width="match_parent"<br /> android:layout_height="wrap_content"<br /> android:paddingBottom="10dip"<br /> android:paddingLeft="10dip"<br /> android:paddingRight="10dip"<br /> android:paddingTop="10dip"<br /> android:text="TextView" /></p><p> <TextView<br /> android:id="@+id/bookPath"<br /> android:layout_width="210dp"<br /> android:layout_height="wrap_content"<br /> android:layout_weight="0.36"<br /> android:paddingBottom="10dip"<br /> android:paddingLeft="10dip"<br /> android:paddingRight="10dip"<br /> android:paddingTop="10dip"<br /> android:text="TextView" /></p><p> </LinearLayout></p><p></LinearLayout></p><p>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.