繁体   English   中英

在膨胀的布局上创建onClick事件

[英]create an onClick event on an inflated layout

每当有一个GeoPoint出现时,我都会单击它,并在该GeoPoint上显示详细信息。 最初,我在膨胀布局中有一个按钮,但现在我发现:

该视图在返回时呈现为图像(使用View.draw(Canvas))。 因此可以为整个展开的布局创建onclick事件。 下面显示了展开式布局的xml文件:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:minWidth="150dp"
android:id="@+id/placeInfo"
>
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtName"
    android:textColor="#ff555555"
    android:textSize="14dip"
    android:textStyle="bold"
    android:layout_marginTop="5dip"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtHours"
    android:textColor="#ff555555"
    android:textSize="14dip"
    android:layout_marginTop="5dip"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtCountry"
    android:textColor="#ff555555"
    android:textSize="14dip"
    android:layout_marginTop="5dip"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtAddress"
    android:textColor="#ff555555"
    android:textSize="14dip"
    android:layout_marginTop="5dip"
    />
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/txtPostCode"
    android:textColor="#ff555555"
    android:textSize="14dip"
    android:layout_marginTop="5dip"
    />

现在,我已经找到了解决此问题的方法,因为您无法在膨胀布局中选择特定元素,因此必须选择完整的膨胀布局。 这是通过以下代码行完成的

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
   @Override 
   public void onInfoWindowClick(Marker marker) { 

   }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM