1
我已经将自定义标题添加到Android中的ListView。 Header的布局xml文件包含一个Image按钮。我如何添加一个OnClickListener这个ImageButton的如何将OnClickListener添加到Android的ListView标题中的图像按钮?
页眉布局文件
<?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);
ImageButton在哪里? –
对不起,我编辑了这个问题。 –
'header.findViewById(R.id.imageButton1).setOnClickListener(new View.OnClickListener(){@Override public void onClick(View v){/ * ... * /}});' –