我已经完成了我的自定义ListView,xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:id="@+id/list" android:layout_width="1px" android:layout_height="1px" android:layout_weight="1"></ListView>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/img" android:layout_width="26px" android:layout_height="30px" />
<TextView android:id="@+id/title" android:layout_width="248dp" android:layout_height="wrap_content" android:textStyle="bold" android:paddingLeft="6dp" android:textSize="20sp" />
<ImageButton android:id="@+id/cat_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:layout_marginRight="2dp" />
<ImageButton android:id="@+id/act_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="4dp" />
</LinearLayout>
</LinearLayout>
” 代码是
public class MyListActivity extends ListActivity
{
protected void onCreate(Bundle savedInstanceState)
{
Log.i("MyApp", "ON List create......");
super.onCreate(savedInstanceState);
List<BeanObj> list=...//Do something to fill list
setListAdapter(new MyListViewAdapter(context, R.layout.item_view, list));
}
public class MyListViewAdapter extends ArrayAdapter<List<BeanObj>>
{
private List<BeanObj> hList=null;
public MyListViewAdapter(Context context, int textViewResourceId, List hList)
{
super(context, textViewResourceId, hList);
this.hList=hList;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
final BeanObj bean=this.hList.get(position);
LayoutInflater inflater=getLayoutInflater();
View row=inflater.inflate(R.layout.item_view, parent, false);
// Do something to fill ListView
return row;
}
}
}
我确实尝试在其上添加一个按钮,但我在列表视图的每一行上都有每个按钮...
我可以在xml上做什么来在我的自定义列表视图上添加浮动按钮? 或者,我在下面提供另一个xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="left|top">
<Button android:id="@+id/btnLogout" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonLogout" />
<View android:layout_width="75dp" android:layout_height="40dp" />
<Button android:id="@+id/btnList" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonList" />
<Button android:id="@+id/btnSearch" android:layout_width="wrap_content" android:layout_height="40dp" android:text="@string/buttonSearch" />
</LinearLayout>
我是如何通过addHeaderView或addFooterView方法使用它的?