2013-11-22 25 views
0

我想在列表視圖中使用按鈕創建應用,如下圖所示。我應該可以通過單擊列表項來點擊並導航到另一個頁面,我應該可以在列表視圖中使用按鈕(或開關)。我不知道這是否是列表視圖本身。如何實現listview(帶按鈕的列表視圖)按鈕(如在屏幕截圖中給出的)

任何幫助一些示例代碼非常感謝。 Below is A screenshot of sample app

+0

對於你創建自定義列表項視圖XML。 –

+0

感謝您的回覆。您能否介紹一下我如何實現這一點的更多細節。我必須做什麼和如何定製?請給一些僞代碼。謝謝。 – joe

回答

3
//try this 
hi this demo list item view you have modify as per requirement and also hide-show inner view like switch button show on some cases.. 

**listitem.xml** 
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center"> 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:adjustViewBounds="true" 
     android:src="@drawable/ic_launcher"/> 

    <TextView 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:singleLine="true" 
     android:layout_marginLeft="3dp" 
     android:text="Power Saving" 
     android:ellipsize="end"/> 

    <Switch 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="3dp" 
     android:checked="true"/> 

</LinearLayout> 
+0

謝謝!!有用。 – joe

1
inflate this view in your list and you will get what you want. 


<LinearLayout 
android:layout_weight="3" 
android:layout_height="wrap_content" 
android:gravity="center"> 

<ImageView 
    android:id="@+id/Imageview1" 
    android:layout_weight="1" 
    android:layout_width="0dp" 
    android:layout_height="50dp" 
    android:adjustViewBounds="true" 
    android:src="@drawable/img"/> 

<TextView 
    android:id="@+id/Textview1" 
    android:layout_width="0dp" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    android:layout_marginLeft="3dp" 
    android:text="your text" 
    android:ellipsize="end"/> 

<Switch 
    android:id="@+id/switch1" 
    android:layout_width="0dip" 
    android:layout_weight="1" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="3dp" 
    android:checked="true"/> 

</LinearLayout>