我有一个xml文件。我正在为ImageButton btnSeat1,btnSeat2,btnSeat3,btnSeat4设置OnClickListener。但是当我按下它时,没有任何反应。我已经尝试设置可点击,但它没有用。
<FrameLayout 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=".MapActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"
android:scrollbars="vertical" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<Button
android:id="@+id/btnFilters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@drawable/filter"
android:onClick="filters_onclick"
android:text="Мои Фильтры" />
<Button
android:id="@+id/btnCabinet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="1dp"
android:layout_toRightOf="@id/btnFilters"
android:background="@drawable/kabinet"
android:onClick="cabinet_onclick"
android:text="Мой Кабинет" />
<ImageButton
android:id="@+id/btnSettings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/btnCabinet"
android:layout_alignParentTop="true"
android:layout_marginLeft="1dp"
android:layout_toRightOf="@id/btnCabinet"
android:background="@drawable/set"
android:onClick="settings_onclick" />
<LinearLayout
android:id="@+id/linearShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@id/btnCabinet"
android:background="#c7c8c8"
android:orientation="horizontal" >
<TextView
android:id="@+id/textfBelowMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#c7c8c8"
android:text="Быстрый фильтр"
android:textColor="@color/Black"
android:textSize="14dp" />
<ImageButton
android:id="@+id/btnMapFilter"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/image_open"
android:onClick="map_filter" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnCabinet"
android:layout_toRightOf="@id/linearShow"
android:background="#c7c8c8"
android:orientation="horizontal" >
<TextView
android:id="@+id/textBelowM"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#c7c8c8"
android:text="Заявок: "
android:textColor="@color/Black"
android:textSize="14dp" />
<ImageButton
android:id="@+id/btnMapRequests"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/image_open"
android:onClick="request_filter" />
</LinearLayout>
<ImageButton
android:id="@+id/btnSeat1"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/btnCabinet"
android:background="@drawable/seat1" />
<ImageButton
android:id="@+id/btnSeat2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_below="@id/btnSeat1"
android:layout_marginLeft="1dp"
android:background="@drawable/seat2"/>
<ImageButton
android:id="@+id/btnSeat3"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_below="@id/btnSeat2"
android:layout_marginLeft="1dp"
android:background="@drawable/seat3" />
<ImageButton
android:id="@+id/btnSeat4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentRight="true"
android:layout_below="@id/btnSeat3"
android:layout_marginLeft="1dp"
android:background="@drawable/seat4" />
<ImageButton
android:id="@+id/btnRefresh"
android:layout_width="60dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="@drawable/refresh"
android:onClick="refresh_onclick" />
<ImageButton
android:id="@+id/btnGo"
android:layout_width="60dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="1dp"
android:layout_toRightOf="@id/btnRefresh"
android:background="@drawable/go"
android:onClick="go_onclick" />
<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/textBelowMap"
android:layout_toRightOf="@+id/btnGo"
android:layout_marginRight="50dp"
android:layout_marginLeft="5dp"
android:background="@drawable/after_update_backgound"
android:text="Отображать только вашего попутчика"
android:textSize="12dp" />
<Button
android:id="@+id/btnFinish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="90dp"
android:layout_marginTop="20dp"
android:text="Конец поездки"
android:textSize="12dp" />
<TextView
android:id="@+id/textBelowMap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btnGo"
android:layout_centerHorizontal="true"
android:text="Поиск без фильтра осуществляется в радиусе 5км от локации"
android:textColor="@color/Black"
android:textSize="8dp"
android:textStyle="bold" />
</RelativeLayout>
</FrameLayout>
Java的代码
btnSeat1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "privet", Toast.LENGTH_SHORT).show();
// TODO Auto-generated method stub
LatLng point = new LatLng(coord1_, coord2_);
if (coord1_ != -1 && coord2_ != -1) {
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(
point, 17);
map.animateCamera(cameraUpdate);
}
}
});
我正在实例化
btnSeat1 = (ImageButton) findViewById(R.id.btnSeat1);
btnSeat2 = (ImageButton) findViewById(R.id.btnSeat2);
btnSeat3 = (ImageButton) findViewById(R.id.btnSeat3);
btnSeat4 = (ImageButton) findViewById(R.id.btnSeat4);
我确定它是正确的,因为我可以在按钮上设置图像。
当我说什么都没发生时,我的意思是这个。它不会崩溃,它只是不起作用。 我用调试器检查它,但无法访问OnClick内的断点 有人说FrameLayout可能是问题所在,因为这个按钮可能位于第二层,也许这就是问题,但我不知道如何处理它