是否可以在列表视图中放置2个按钮

时间:2010-10-14 06:20:54

标签: java android

的ListView

[文字] [按钮1] [按钮2]

[文字] [按钮1] [按钮2]

...(依此类推)......

按钮1应该像Check Box和其他允许在其他页面上重定向的按钮

上面提到的事情可能吗?

提前致谢..

2 个答案:

答案 0 :(得分:0)

列表视图中的每一行都可以满足您的心愿。行基本上定义为自己的布局,您可以根据需要定义布局。在您的情况下,您可能想要做一个RelativeLayout。查看示例,它们非常接近您想要的内容。

答案 1 :(得分:0)

您可以让ListView行包含CheckedTextView和Button ina Linear Layout。

在\ layout \文件夹中,定义您的自定义my_row.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="fill_parent" 
    android:orientation="horizontal"> 
<CheckedTextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    /> 
<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 

然后填充ListView,在适配器中提供。

ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(this, R.layout.my_row, strings);
myList.setAdapter(myAdapter);