我在 android 的 ListView 中添加了一个自定义标题。Header 的布局 xml 文件包含一个 Image 按钮。如何向此 ImageButton 添加 OnClickListener
标题布局文件
<?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="fill_parent" android:background="#336699">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add" />
</LinearLayout>
绑定 ListView 的代码(我创建了一个自定义适配器)
ListView listView1 = (ListView) findViewById(R.id.listView1);
LocationAdapter adapter = new LocationAdapter(this,R.layout.listrow,webresult);
View header = (View)getLayoutInflater().inflate(R.layout.listheader, null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);