2011-12-14 54 views
-1

我想知道是否可以自定義每行的列表視圖?我想將複選框添加到少數行中,另一個按鈕等。如何爲此構建* .xml文件?如何自定義Android ListView的每一行?

在此先感謝!

+1

是的,它是可能的。你可以搜索網頁有很多這個教程。你會浪費你的時間讓別人回答。 – 2011-12-14 12:25:26

回答

1

您可以編寫如下所示的正常佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:id="@+id/lineItem"> 
    <!-- The attribute name --> 
    <TextView android:id="@+id/attributeName" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" android:layout_alignParentLeft="true" 
    android:textStyle = "bold" android:paddingTop = "2dp" android:textSize="16dp"/> 

    <!-- The attribute value just beneath the attribute name --> 
    <TextView android:id="@+id/attributeValue" android:layout_height="wrap_content" 
    android:layout_width="wrap_content" android:layout_alignParentLeft="true" 
    android:layout_below="@id/attributeName" android:textSize="12dp" android:paddingBottom="2dp" /> 

    <!-- Now create button besides the line with right align --> 
    <Button android:layout_width="wrap_content" 
    android:background="@drawable/printbutton" 
    android:layout_height="wrap_content" 
    android:id="@+id/printbtn" 
    android:layout_centerInParent="true" android:layout_alignParentBottom="true"></Button> 
</RelativeLayout> 

然後在你的ListView適配器功能

public View getView(final int position, View convertView, ViewGroup parent) 

可以使用線

convertView = mInflater.inflate(R.layout.listviewrow,null); 

這是什麼我已經做好了。

0

是的!可以使用佈局自定義每一行(也可以使用CheckBox) 您需要開發自定義ArrayAdapter。 你可能會發現一個教程here

我希望它會對你有用。