我的地图布局中包含页脚布局。页脚有 3 个 ImageButtons。我想尽一切办法找出点击次数,但没有成功。我只需要页脚在此活动中工作,因此如果可能,我认为没有必要创建额外的类文件。
页脚.xml
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout android:id="@+id/LinearLayout01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:weightSum="4"
android:clickable="true"
android:background="@drawable/footer">
<ImageButton
android:id="@+id/guardianButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:clickable="true"
android:layout_weight="1"
android:background="@drawable/guardianbutton" >
</ImageButton>
<ImageButton
android:id="@+id/sosButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:background="@drawable/sosbutton"
android:paddingLeft="5dp"
android:layout_weight="2"
android:paddingRight="5dp" />
<ImageButton
android:id="@+id/settingsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/sosButton"
android:layout_gravity="bottom"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="@drawable/settingsbutton" >
</ImageButton>
</LinearLayout>
</merge>
mapviewmain.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapViewMain"
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@layout/header"
class="com.google.android.gms.maps.SupportMapFragment" />
<!-- Header Starts-->
<LinearLayout
android:orientation="vertical"
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@layout/header"
android:paddingTop="5dip"
android:paddingBottom="5dip">
</LinearLayout>
<!-- Header Ends -->
<!-- Footer Start -->
<RelativeLayout android:id="@+id/RelativeLayout03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<include layout="@layout/footer" /></RelativeLayout>
<!-- Footer Ends -->
</RelativeLayout>
一切都正确显示。我只是无法访问 ImageButtons 的 onclick 侦听器。到目前为止,我尝试了以下方法:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.footer, container, false);
container.addView(view);
ImageButton loadmore = (ImageButton) view.findViewById(R.id.sosButton);
loadmore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Toast.makeText(MapViewMain.this, "SOS Button pressed", Toast.LENGTH_LONG).show();
}
});
return view;
}